Gitlab Jenkins Property Generator

We use Gitlab at work and I've recently been working on improving our deployments. We have several old monolithic applications which are a challenge to deploy for QA especially as we are getting into the habit of using feature branches to manage our code.

What happens is Joe will deploy feature/ABC-253 to our QA server. Then Sally will need to get feature/ABC-764 tested as well. The developers can certainly hop on the server and easily switch branches but I wanted our QA person (who isn't that technical) to be able to do this as well.

Digging through the Gitlab API I figured out I could grab a list of current branches for a particular project. Tie that into a parameterized build on Jenkins and I thought I could setup a simple "GUI" for our QA person to be able to switch branches on a project.

Note: At the time I wrote this I was also interested in learning ColdBox so I wrote the app using that framework. If I were to do it over again I'd probably do it using CommandBox.

Usage

This assumes you have a working Lucee / Railo installation. If you don't, the quickest way to get this up an running is via CommandBox. Follow the installation instructions for CommandBox, download the JGPG code, open a command prompt in the JGPG directory and type 'box server start'. This will start a server. Note the port # in the prompt: 127.0.0.1:58374. Open that URL in your browser and hopefully you will see something like:

Now you can setup a scheduled task to run this code and generate a new .properties file as needed. I run this once a day. We don't create feature branches that often and I find this is an acceptable schedule. YMMV.

Jenkins Configuration

Install the Extended Choice Parameter Script plugin in Jenkins. In my case I am simply using this to set a property in my job which I can pass on to Ant / Git to deploy the appropriate branch to my QA server.

Configuring the plugin is straightforward.

Enter a name of the parameter you want to define, also provide a description i.e.: 'branch'

For the parameter type I just want to display a dropdown of all the available branches to my QA user. So I select "Single Select".

Next you define where your property file lives. This is the file generated by our JGPG code. I'm on Windows so I simply setup a share somewhere and point both my code and Jenkins at the same shared folder.

The "Property Key" ties to the list of projects in your properties file: