The Jenkins build systemhas an open API which means we can do stuff with it. Today we’re going to automate the deployment of an application with a specific stable version. Jenkins has a great UI, it’s very flexible indeed, but sometimes is not enough. For instance, for CloudHub we deploy a Jenkins build to our QA environment, according the period in our development cycle, and we also need to execute automated tests. However, we can create a quick web application to choose a version of an application in Jenkins to deploy, using Mule Studio and CloudHub.
So, here is a Mule application that gather information from Jenkins and even start builds using a UI that satisfy our need creating:
Now, lets dig into this application
Creating the UI
The first flow is an HTTP Endpoint that serves static resources, in this case the HTML page that makes AJAX calls to get the information from Jenkins. This info is exposed throw others endpoints in this same Mule application.
Get the information from Jenkins
There are two Endpoints to get information from Jenkins exposed by the connector. The HTML page uses ajax to hit those endpoints and obtain the information in JSON format.
But first there is a configuration to make the connection to Jenkins server work:
This endpoint is used to get the Jobs list and obtain their names. Mule connects to Jenkins API and returns in JSON format the requested information. (Jenkins API access: https://JenkinsServer/api/json)
With this endpoint we get the information about the Job. In this web app we need to get two pieces of information, the build number and its status (success, failed). (Jenkins API access: https://JenkinsServer/jobName/api/json)
Perform job build
Finally, we expose an Endpoint with the ability to initiate a job build in Jenkins. This is the real work to call the deployer job:
Calling endpoints using AJAX
Now, the final piece is to make the UI to work, connecting all the elements in the page with the information that mule returns.
The following is an example of how to access the previous endpoints using JQuery ajax call:
Using Mule Studio, we are able to create quickly this kind of small apps without any line of code. And, this application gave us the ability to leverage the independence of QA team in order to maintain its environment.
Learn why we are the Leaders in API management and iPaaS