2014-11-25 80 views
1

我們正在使用Jenkins和Git以及功能分支,但是我對Git插件如何在構建過程中公開提交信息感到不高興,因爲我們使用「合併在構建「git選項之前。如何配置Jenkins以顯示合併分支的名稱和提交

的GIT插件

  1. 檢查出特性分支建立
  2. 融合了功能分支到主

正因爲如此,當前分支現在是產地/主,和當前的HEAD是一個本地提交,除了在我們的構建服務器上以外,還沒有任何地方存在。 這可能通過推動合併代碼備份到GitHub - 甚至可能是一個臨時分支,但我們不希望這種行爲,我們想要手動控制。

所以,問題是: 如何

  1. 揭露分支名,並承諾哈希後續構建步驟
  2. 裝飾用鏈接構建的信息,以便用戶可以瀏覽提交(s)表示,觸發了構建。

回答

1

如果只想分行的名稱,而沒有爲構建過程中的任何所需的分支名稱,以下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 - 所以如果你只想要「功能 - 富」

該項目將無法正常工作解決方案似乎是:

  1. 安裝Groovy插件
  2. 安裝EnvInject插件
  3. 配置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插件本身...

相關問題