In a previous post (located here) I discussed setting up a deployment pipeline with Jenkins which would retrieve a specified version of one of our web applications from our Nexus repository and deploy it to a specified Glassfish server. One of the challenges with the Jenkins job was that most of the fields on its deployment page were text fields, allowing users to free form text which was prone to errors. The original deployment page appears below and allows the user to select the server and application via dropdown box, but leaves all other properties open to free form text.
The other drawback to the screen above was that each application needed to be listed in a text file which Jenkins would read in order to populate the Application dropdown box. This meant that there was a manual step involved with deploying an application that had not been deployed before.
With this in mind I decided to modify the Jenkins Dynamic Parameter Plugin to allow us to auto populate dropdown boxes with valid values based on our environment here at Lynden. I started with this plug-in since it already had functionality to change the contents of dropdown boxes based upon user selections. ie The selection of one dropdown could be used to determine the contents of another dropdown box. The requirements for this modified plug-in were that it should:
- Get a list of applications that are in our Nexus release repository
- Get a list of versions of the selected application from Nexus.
- Get a list of the application versions that are currently deployed to the Glassfish instance the user has specified for deployment.
- Enable the user to select a web context to use when deploying the app, or select “Other” if they want to enter a context that does not appear in the list.
The Server dropdown box for this new Deployment plug-in allows the user to select which instance of Glassfish they would like to deploy to. Each line in the dropdown contains the server name, Glassfish instance name, HTTP port, and admin port of the instance.
Once the user has selected a server, they can then select an application from the Application dropdown box. For this field, the Jenkins plug-in goes out to our Nexus repository and retrieves the names of all of our applications, populating the list with these values.
Once the application has been selected, the user can select which version of the application to deploy. This list of versions is also obtained from Nexus by the plug-in, which displays up to 25 of the most recent versions.
After the user has selected the version to deploy, they can optionally specify a version to undeploy. The plug-in populates this field by looking at the Glassfish instance that the user selected and querying it to determine if any versions of the specified application are currently deployed to it. In the example below, HelloWorldWeb 1.1.5 and 1.1.4 are both currently deployed to the Glassfish instance running on “webstg”. This field is optional, and if a value is selected, the Deploy task will first undeploy the specified version before deploying the new version.
Finally, the user can select a context to use when deploying the application, which is the portion of the URL after the hostname that the app server uses to identify requests for the application. The two most common context names are included in the drop down, which are <app-name> and <app-name>-<version-number>. So for example, if HelloWorldWeb-1.1.3 were selected below, the application would have a URL of http://webstg.lynden.com/HelloWorldWeb-1.1.3
If a different application context is needed, the user can select “Other” from the dropdown box (in the screenshot above), and then enter an app context name in the “Other” text box below the Context drop down box.
At this point the user can select the “Build” button which will invoke an Ant script detailed in the previous post, downloading the binary from Nexus, undeploying the previously deployed version from Glassfish (if specified), deploying the new version of the application to Glassfish, and then saving information about the deployment to a database which can be viewed from a separate web application.
Since nearly all the fields are dynamically populated, there isn’t too much work for configuring the job in Jenkins. Below is the Configuration screen for this deployment job. There are 2 parameters which must be defined for this job. The first is the environment this job will deploy to, ie. Test, Staging or Prod. The second is a list of valid Glassfish instances which can be deployed to. The location of the maven repository and the location of the Glassfish command line interface are defined as system properties in Jenkins.
By using a Jenkins plugin to prepopulate the fields which are required for deploying an application we will streamline the deployment process and make it less prone to error.