我有一個在我的 jenkins 管道上運行的 bat 腳本。
它用于標記我的分支的特定提交,并將其推送回 git。看起來像這樣:
"scriptCommand": https://%C_USERNAME%:%C_PASSWORD%@bitbucket.psr.io/scme/ci/ci.git\ngit push origin TAG1\ngit remote set-url --push origin https://bitbucket..psr.io/scme/ci/ci.git"
該命令是使用變數 C_USERNAME、C_PASSWORD 和 TAG1 生成的
當我使用 http 鏈接而不是 SSH 鏈接作為我的 repo 時,這很有效
我還需要能夠處理 SSH 鏈接。為此,我研究了 SSH 私鑰,結果發現 jenkins 憑證有一個特定的欄位:帶有私鑰的 SSH 用戶名
我使用我的私鑰和用戶名在 jenkins 中創建了一個這樣的憑據
但是現在我在如何使用 http 鏈接創建一個與上面相同的批處理行時遇到了麻煩。
不用說,我在這件事上的經驗是 0。
有人可以幫我嗎?謝謝你的時間。
uj5u.com熱心網友回復:
SSH URL 類似于:
[email protected]/scme/ci/ci.git
但是您可能想要使用專用插件,例如通過 SSH 發布,您可以將其包含在管道中。
在你的情況下:
git remote set-url --push origin [email protected]/scme/ci/ci.git
使用SSH 代理插件
node {
sshagent (credentials: ['myKey']) {
sh 'git push [email protected]/scme/ci/ci.git aTag'
}
}
假設您已在 Jenkins Global credentials (unrestricted) 中將您的私鑰注冊為名為“ myKey”的條目。
使用withCredentials,如此處所示,假設Git 2.10 用于GIT_SSH_COMMAND:
withCredentials([sshUserPrivateKey(credentialsId: "myKey", keyFileVariable: 'key')]) {
//auth to git here then do some commands for example:
sh 'git commmit -am "hello my commit message'
sh 'GIT_SSH_COMMAND = "ssh -i $key"'
sh 'git push [email protected]/scme/ci/ci.git aTag'
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/459126.html
上一篇:Jenkinsgroovy檔案無法匯入另一個groovy
下一篇:Jenkins有多個代理的階段
