我正在使用 jenkins 管道(声明性 synthax)并且我想将提交推送到我的远程存储库。
有什么方法可以使用 git 插件来完成此操作吗?
这是我目前正在尝试的:
withCredentials([usernamePassword(credentialsId: "${GIT_CREDENTIAL_ID}", passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git add ${BRANCH_RENAME}.bundle"
sh "echo ${GIT_USERNAME}|||||||${GIT_PASSWORD}"
sh "git tag -a backup -m 'Backup branch ${BRANCH} from vega-salesforce to vega-salesforce-backup' "
sh('git push https://${GIT_USERNAME}:${GIT_PASSWORD}@${GIT_URL_WITHOUT_HTTPS} --tags')
}
但它不起作用。
我收到以下错误:`
fatal: unable to access 'https://****:****@myrepositoryurl/mygitgroup/salesforce-backup/': Could not resolve host: ****:clear_password_here; Name or service not known
有人可以帮忙吗?
我虽然问题来自我的密码中存在的特殊字符,但我不确定。
最佳答案
我们终于想通了。
问题很简单,我们的密码中有特殊字符会破坏 url。
这是工作代码:
withCredentials([usernamePassword(credentialsId: env.GIT_CREDENTIAL_ID, usernameVariable: 'USER', passwordVariable: 'PASS')]) {
script {
env.encodedPass=URLEncoder.encode(PASS, "UTF-8")
}
sh 'git clone https://${USER}:${encodedPass}@${GIT_URL} ${DIR} -b ${BRANCH}'
sh 'git add .'
sh 'git commit -m "foobar" '
sh 'git push'
}
关于使用来自声明性管道的 jenkins 凭据进行 Git 推送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55970749/