Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get output of 'git describe' into Jenkins build name

Tags:

jenkins

What's the best (or any!) way to put the output of a command in a Jenkins build name?

I'd like to put the output of the git describe command into the build name of a Jenkins job.

I've installed the build-name-setter plugin with the hopes of setting the build name to something like:

${ENV, var="GIT_DESCRIBE"}

I just don't know how to set $GIT_DESCRIBE before the name is set! I've tried using the EnvInject plugin. The only way to dynamically set the environment variables is to use groovy script. This would work well, except my job is running on a remote slave and the groovy script is (apparently) running only on the master.

like image 562
gdw2 Avatar asked Jul 21 '15 21:07

gdw2


1 Answers

If you need the "describe" data (i.e. you can't just use the existing $GIT_BRANCH or $GIT_COMMIT environment variables), you could add an "Execute shell step" with:

echo GIT_DESCRIBE=$(git describe) > git.properties

Then after that, add an EnvInject build step which injects properties from the git.properties file.

like image 139
Christopher Orr Avatar answered Oct 21 '22 01:10

Christopher Orr