Set Jenkins build display name with Groovy

On the Xtext’s Jenkins instance we have some parametrized jobs that are used for the different projects that are built on Jenkins (Xtext, Xpand, MWE). For example, the simrel-tests job does some health checks on the resulting p2 repositories.

The problem was that it was not obvious for which job name parameter the build was executed. On first sight you only see the build number, and then you have to look in each individual build to identify which parameter was used:

screenshot 15

With the help of a Groovy script using the Jenkins Groovy Plugin we can change the display name of a build:

build name changed

Also on the Dashboard page it becomes clear for which parameter the last build was run:

screenshot 17.png

To do this, add a build step “Execute system Groovy script” and access the job’s environment variables with build.properties.environment.toString(). Then set a new display name by assigning a new value to build.displayName. That’s all.

groovy command

Advertisements

2 thoughts on “Set Jenkins build display name with Groovy

  1. Thanks for sharing this insight.

    We do not have the required information available as environment variable for setting the build name. So, we use a build-in functionality from Jenkins.

    We want to set the version string as build name. Our Gradle build log contains a line
    ‘Going to build project “project-name” with version: 2.6.11’

    The trailing version string logged here can easily be taken over as build name by setting the “Set Build Name” in the particular Jenkins task configuration to a regular expression. For us this is
    ${BUILD_LOG_REGEX,regex=”.*Going to build project .* with version: (.*)$”,maxMatches=1,showTruncatedLines=false,substText=”$1″,addNewline=false}
    In our example this would take over “2.6.11” as build name.

    Also quite easy. 🙂

    … My two cents.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s