Monday, August 22, 2016

Show version number in jenkins job history

Everybody handles versioning in a different way but if your jenkins job sends the version to the output stream you can use the below steps to show such version in the build history. This is handy specially for test jobs as you want to make sure that tests did pass for that specific version.

Let us assume that your job prints something like "Front-End Version: 1.2509". Here is how you print the version number in the jenkins job history:
  1. Install "Groovy Postbuild" plugin.
  2. Add a post build action type "Groovy postbuild"
  3. Insert the below in "Groovy Script" and save
    def m = manager.getLogMatcher("^.*Front-End Version: (.*)\$")
    // to debug using job logs
    // manager.listener.logger.println("found version:" + m.group(1))
    if(m != null && m.matches()) {
      version = m.group(1)
      manager.addShortText(version)
    }
    
  4. Run the job and you will get the version number next to the build.

4 comments:

Ross Bender said...

Doesn't the Description Setter plugin accomplish the same thing? https://wiki.jenkins-ci.org/display/JENKINS/Description+Setter+Plugin

Nestor Urquiza said...

@Ross Thanks for pointing that out. Yes either Description or Name Setter Plugins could achieve something similar. Of course the Groovy Post Build Plugin allows for parsing multi lines and display the information as Name or Description but definitely the Description or Name Setter Plugins look like simpler (and to me better) alternatives for the subject of this post. Thanks for sharing!

Deryl Spielman said...

Typically you would use the description name plugin when you already know the version of the app you are using. To me setting the version in the build description from log output is caused from a broken pipeline where the version of the application is not at the starting point of the pipeline nor passed to all dependent jobs.

Nestor Urquiza said...

@Deryl we live in a wonderful but imperfect world. At least the plugins mentioned here help you deal with an imperfection in a cost effective way.

Followers