如果只想分行的名稱,而沒有爲構建過程中的任何所需的分支名稱,以下Groovy腳本是有用的:
def matcher = manager.getLogMatcher(/.*Merging Revision ([0-9a-f]+)\s+\((.*)\).*/)
if (matcher?.matches())
{
commit = matcher.group(1)
mergeBranch = matcher.group(2)
println "buildLog claims we are buidling ${commit} on '${mergeBranch}'"
manager.build.setDisplayName(mergeBranch);
}
if (manager.logContains(".*ERROR: Branch not suitable for integration.*"))
{
manager.addShortText("Merge conflict");
}
這將設置生成的名字 - 這是如果由於「分支不適合集成」而永遠不會啓動構建,則非常有用。
另一種選擇(簡單明顯的一個)是使用GIT_BRANCH
環境變量 - 但這將包含產地/功能FOO - 所以如果你只想要「功能 - 富」
該項目將無法正常工作解決方案似乎是:
- 安裝Groovy插件
- 安裝EnvInject插件
- 配置EnvInject插件與下面的腳本
Groovy腳本:
build = Thread.currentThread().executable
workDir = new File(build.getWorkspace().getRemote())
gitlogProcess = "git log -n 2 --format=\"%H %h %d\"".execute(null,workDir)
log = gitlogProcess?.text // Get the result
items = log?.readLines()?.getAt(1)?.split() // Second line is the commit that was merged onto master
// Parse it
commit = items?.getAt(0)
shortCommit = items?.getAt(1)
mergeBranch = items?.getAt(2)?.minus("(")?.minus(")")?.minus(" ")?.minus("origin/")
// Update build name and description
//buildNumber = build.getEnvironment(listener)?.get("BUILD_NUMBER") <-- This does not work, presumably because the environment is not yet created - if you need this, execute this script as a build step
displayName = "${mergeBranch}-${shortCommit}"
build.setDisplayName(displayName)
githuburl = build.getParent()?.getProperty("com.coravy.hudson.plugins.github.GithubProjectProperty")?.getProjectUrl()?.commitId(commit)
description = "<a href='${githuburl}'>${shortCommit}-${mergeBranch}</a>"
build.setDescription(description)
// Return a map - this will be added to the environment variables
return [
MERGE_BRANCH:mergeBranch,
MERGE_COMMIT:commit,
MERGE_COMMIT_SHORT:shortCommit
]
評論?
理想情況下,這些屬性將暴露Git插件本身...