在我的詹金斯管道中,我有以下代码:
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 [email protected]
git config --global credential.helper cache
git config --global push.default simple
命令行中的具有以上配置git凭据批准和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')