我在BitBucket上有兩個分支:master
和develop
。我還在我的Jenkins服務器上配置了一個BitBucket團隊文件夾作業來構建該存儲庫。在develop
分支有以下Jenkinsfile:在Jenkinsfile中籤出不同的分支是不可能的嗎?
node {
stage('Checkout') {
checkout scm
}
stage('Try different branch') {
sh "git branch -r"
sh "git checkout master"
}
}
當詹金斯運行它,在構建時,它試圖籤master
失敗:
[Pipeline] stage
[Pipeline] { (Try different branch)
[Pipeline] sh
[e_jenkinsfile-tests_develop-4R65E2H6B73J3LB52BLACQOZLBJGN2QG22IPONX3CV46B764LAXA] Running shell script
+ git branch -r
origin/develop
[Pipeline] sh
[e_jenkinsfile-tests_develop-4R65E2H6B73J3LB52BLACQOZLBJGN2QG22IPONX3CV46B764LAXA] Running shell script
+ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
[Pipeline] }
我曾預計git branch -r
命令打印出兩個origin/master
和origin/develop
,但由於某種原因它只打印後者。
我讀過周圍,試圖想出什麼方法可以做到這一點:例如,我嘗試安裝了SSH代理插件詹金斯,改變了Jenkinsfile到:
node {
stage('Checkout') {
checkout scm
}
stage('Try different branch') {
sshagent(['Bitbucket']) {
sh "git branch -r"
sh "git checkout master"
}
}
}
但它仍然沒有按似乎找不到origin/master
。更糟的是,SSH代理好像它試圖籤master
之前被殺害:
[Pipeline] { (Try different branch)
[Pipeline] sshagent
[ssh-agent] Using credentials ThomasKasene (Used to communicate with Bitbucket)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-M6pIguCUpAV4/agent.11899
SSH_AGENT_PID=11902
$ ssh-add /var/jenkins_home/workspace/e_jenkinsfile-tes[email protected]tmp/private_key_2394129657382526146.key
Identity added: /var/jenkins_home/workspace/e_jenkinsfile-tes[email protected]tmp/private_key_2394129657382526146.key (/var/jenkins_home/workspace/e_jenkinsfile-tes[email protected]tmp/private_key_2394129657382526146.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
[e_jenkinsfile-tests_develop-4R65E2H6B73J3LB52BLACQOZLBJGN2QG22IPONX3CV46B764LAXA] Running shell script
+ git branch -r
origin/develop
[Pipeline] sh
$ ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 11902 killed;
[ssh-agent] Stopped.
[e_jenkinsfile-tests_develop-4R65E2H6B73J3LB52BLACQOZLBJGN2QG22IPONX3CV46B764LAXA] Running shell script
+ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
[Pipeline] }
我的最終計劃是承諾的東西develop
,然後將其合併到master
,但到目前爲止,我有非常一點運氣。有沒有人有可能的解決方案或解決方法?
PS:這似乎只是Jenkinsfile中的一個問題;我有一個自由式的工作,可以完成類似於我想要的任務,並且工作正常。
兩個解決方案做出來的你有什麼建議cloing到一個單獨的任何特別的原因目錄,除了搞砸東西的潛在風險之外? –
@ThomasKåsene如果您將兩個存儲庫克隆到相同的目錄,這會導致您的'.git'目錄出現問題。 –
假設我不先擦拭它,我完全同意。該計劃從未將多個分支克隆到同一個文件夾,而是在同一個倉庫中的分支之間來回切換,這在理論上應該工作得很好。順便謝謝你的回答! –