我試過按照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"}