Streamlining a Deployment Pipeline with a Custom Jenkins Plug-In
Join the DZone community and get the full member experience.Join For Free
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.
Opinions expressed by DZone contributors are their own.