Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing "Build Executor Status" of Jenkins

We have a big RAILS project and we are following Github flow to drive our development process. I looked through all the available plugins but could not find anything that customizes the "Build executor status" part of the Jenkins home page.

I wanted to put the name of the git branch instead of job name and executor number since the former makes more sense in our case. Has anybody done this?

like image 526
kaji Avatar asked Nov 14 '22 02:11

kaji


1 Answers

You can use the Build Name Setter Plugin to change the name based on available Tokens. I'm not sure if a TOKEN exists for your Git branch name, but if all else fails, you can use a shell script build step and write it to a property file, and then use the macro: ${PROPFILE,..}, e.g.:

#${BUILD_NUMBER}_${PROPFILE,file="parameters.properties",property="BUILD_TYPE"}

Alternatively, you can use the Description Setter Plugin to change the build description (that also appears in the Build Executor status) based on the build output. Again, you can use the same trick and use a shell script to print out the branch name in the build output, and use a regex to parse it out of your build log.

A small limitation: either of this will only update the name/description after the job completes, so for long-running jobs, it's not immediately visible. But for short ones, and for audit purposes, this works well.

[EDIT] Some time later, I started using the EnvInject plugin, which adds my build parameters to the environment early enough for the Build Name Setter Plugin to use them.

This has the advantage of setting the build name immediately.

Also, you can get the Git branch with ${GIT_BRANCH}. Here's the doc for it:

${GIT_BRANCH}
  Expands to the name of the branch that was built.

Parameters:

all
  If specified, all the branches that point to the given commit is listed. 
  By default, the token expands to just one of them.

fullName
  If specified, this token expands to the full branch name, such as 'origin/master'.
  Otherwise, it only expands to the short name, such as 'master'.
like image 196
Patrice M. Avatar answered Dec 30 '22 17:12

Patrice M.