![](/img/trans.png)
[英]How does credential management work with Jenkins, jenkins slave nodes and git?
[英]git credential approve does not work for Jenkins pipeline
在我的Jenkins管道中,我有以下代碼:
stage('pushing'){
steps {
withCredentials([usernamePassword(credentialsId: '91f32d3c-b7ee-49ac-b233-3bd93d2696eb', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh("echo -e 'url=https://domain.tld\nusername=${GIT_USERNAME}\npassword=${GIT_PASSWORD}' | git credential approve")
sh('git push --tags')
}
}
}
輸出如下:
[Pipeline] sh
13:28:52 [git-push-tag] Running shell script
13:28:52 + git push --tags
13:28:52 fatal: Authentication failed for 'https://domain.tld/scm/~user/git-push-app.git/'
我已經准備了最低配置的環境:
git config --global user.name jenkins
git config --global user.email jenkins@domain.tld
git config --global credential.helper cache
git config --global push.default simple
通過上面的配置, git credential批准和git push --tags從命令行對我有用 。 但這在詹金斯管道中不起作用。
我不知道為什么。
這只是引號問題,因為字符串中包含單引號,所以不會插入諸如${GIT_USERNAME}
類的env變量。
sh("echo -e 'url=https://domain.tld\nusername=${GIT_USERNAME}\npassword=${GIT_PASSWORD}' | git credential approve")
fixed below:
sh('echo -e "url=https://domain.tld\nusername=${GIT_USERNAME}\npassword=${GIT_PASSWORD}" | git credential approve')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.