我正在使用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
有人可以帮忙吗?虽然问题出在密码中的特殊字符,但我不确定。
我们终于弄清楚了。问题很简单,我们在密码中包含特殊字符,这些特殊字符会破坏网址。
这是工作代码:
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' }