我试过按照Christopher Orr概述的步骤,但我的“Execute shell”脚本似乎只在构建开始后才运行。在我的情况下,GIT_DESCRIBE从未为构建使用而设置/注入。
经过一段时间的研究,我找到了一个解决方案,使用“评估Groovy脚本”步骤作为环境注入器插件的一部分。 Groovy脚本是在构建前评估的。但是,主要的注意事项是.groovy脚本不在$ WORKSPACE中运行。我最终做的是从.groovy脚本执行位于我的应用($ WORKSPACE)中的shell脚本,并使用GIT_DESCRIBE将其输出作为映射返回。
评估的Groovy脚本
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's directory
cd "${0%/*}"
echo `git describe`
从那里,你应该能够引用GIT_DESCRIBE在 “构建名” 宏。
${ENV, var="GIT_DESCRIBE"}