2017-04-25 21 views
5

我希望能這樣說:詹金斯管道:結帳明確git的承諾

git branch: commitHash, credentialsId: credentialsId, url: url 

的用例:我在做並行構建和測試運行在不同的平臺,並希望確保每個得到相同的代碼。它是C++,我們建立在不同的平臺上,並且建立在它們之上。

如果我做上面的,它失敗 - 底層代碼假設給定的分支實際上是一個分支,或者你喜歡的東西:在這個問題上

[Linux64 Build] > git rev-parse origin/e4b6c976a0a986c348a211579f1e8fd32cf29567^{commit} # timeout=10 
[Pipeline] [Linux64 Build] } 
[Pipeline] [Linux64 Build] // dir 
[Pipeline] [Linux64 Build] } 
[Pipeline] [Linux64 Build] // node 
[Pipeline] [Linux64 Build] } 
[Linux64 Build] Failed in branch Linux64 Build 

我已經看到了變化之前問,雖然沒有真正的答案 - 只是建議喜歡隱藏源代碼等,而不是真正的我以後。

該文檔表明應該可以給出明確的提交散列,可能使用分支代替,但我不能找出語法並找不到任何示例。當我這樣做時,我認爲主分支 - 在我們的設置中,主分區不起作用。

到目前爲止,我已經找到了唯一的解決辦法已經簽出分支,然後顯式調用混帳得到承諾:

   git branch: branch, credentialsId: credentialsId, url: url 
       sh 'git checkout ' + commitHash 

(其中分公司是我最初得到的哈希在分支這項工作的頂端。它的工作原理,但不是最巧妙的。

任何人有更好的辦法?

+0

見在2017年7月12日和2017年7月13日評論[JENKINS-31826(https://issues.jenkins-ci.org/browse/JENKINS-31826) –

回答

7

使用general scm一步

checkout([$class: 'GitSCM', branches: [[name: commitHash ]], 
    userRemoteConfigs: [[url: 'http://git-server/user/repository.git']]]) 
+0

你碰巧知道如何添加credentialsId位? – johnfo

+0

我依靠詹金斯用戶的ssh密鑰 –

+1

我想我設法解決了這個問題 - 至少我注意到這裏有一個片段「編輯器」。它會是這樣的: 結帳([$ class:'GitSCM',branches:[[name:commitHash]], userRemoteConfigs:[[credentialsId:credentialsId,url:'http:// git-server/user/repository.git']]]) – johnfo

2

當jenkins由於初始結賬而缺少工作空間時,尤里G的例子並不適用於我。在這種情況下,以下工作。我不明白他們爲什麼會有所不同。

def commitId = "<insert sha here>" 

    checkout ([$class: 'GitSCM', 
     branches: [[name: commitId ]], 
     userRemoteConfigs: [[ 
      credentialsId: 'deploy key for your repo', 
      url: 'repo url']]]) 
+0

我一直在使用: steps.checkout([$ class:'GitSCM',branches:[[name:hash]], userRemoteConfigs:[[url:url,credentialsId:'key of憑據']]]) – johnfo

+0

這與我所得到的差不多。我只是分開線條並使用不同的順序。訂單應該不重要 –

+0

我們和Yuri的區別在於債權證 - 可能就是這樣。公共回購vs私人。傻我 –