使用来自声明性管道的 jenkins 凭据进行 Git 推送 [英] Git push using jenkins credentials from declarative pipeline

查看:36
本文介绍了使用来自声明性管道的 jenkins 凭据进行 Git 推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 jenkins 管道(声明式合成器),我想将提交推送到我的远程存储库.

I'm using jenkins pipeline (declarative synthax) and I want to push a commit to my remote repository.

有没有办法使用 git 插件来完成这个?这是我目前正在尝试的:

Is there any way to accomplish this using the git plugin? Here is what I'm currently trying:

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')
                    }

但它不起作用.我收到以下错误:`

But it does'nt works. I got the following error:`

fatal: unable to access 'https://****:****@myrepositoryurl/mygitgroup/salesforce-backup/': Could not resolve host: ****:clear_password_here; Name or service not known

有人可以帮忙吗?我虽然问题出在我的密码中的特殊字符,但我不确定.

Could anyone help please? I though the issue comes from the special characters present in my password but I'm not sure.

推荐答案

我们终于弄明白了.问题很简单,就是我们的密码中有特殊字符会破坏 url.

We finally figure it out. The problem was simply that we have special characters in our password which break out the 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 推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆