How to get the output of 'git describe' in the Jenkins assembly name

What is the best (or any!) Way to put the output of a command in a Jenkins build name?

I would like to put the output of the command git describein the assembly name of the Jenkins job.

I installed the plugin build-name-setterwith the hope of setting the assembly name to something like:

${ENV, var="GIT_DESCRIBE"}

I just don’t know how to install $GIT_DESCRIBEbefore the name is installed! I tried using the plugin EnvInject. The only way to set environment variables dynamically is to use the groovy script. This will work well, except that my work is done on a remote slave, and the groovy script only works (apparently) on the master.

+4
source share
3 answers

"" (.. $GIT_BRANCH $GIT_COMMIT), "Execute shell step" :

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

EnvInject, git.properties.

+5

, , "Execute shell" script, , , . GIT_DESCRIBE / , .

, " Groovy script" . Groovy script . , .groovy script $WORKSPACE. , , - script, ($ WORKSPACE) .groovy script, GIT_DESCRIBE.

Groovy script

def sout = new StringBuilder()
def serr = new StringBuilder()
def proc = "$WORKSPACE/git-describe.sh".execute()
proc.waitForProcessOutput(sout, serr)
def map = [GIT_DESCRIBE: sout.toString()]
return map

git -describe.sh

#! /bin/bash

# change working directory to the current script directory
cd "${0%/*}"

echo `git describe`

GIT_DESCRIBE "Build name".

${ENV, var="GIT_DESCRIBE"}
0

plug-in-setter v1.6.7 :

  • " ", git describe >version.txt

  • " ", version.txt.

0

Source: https://habr.com/ru/post/1598968/


All Articles