Git push using jenkins credentials from declarative pipeline

后端 未结 2 1895
南方客
南方客 2020-12-20 17:26

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

Is there any way to accomplish this using the git plugin? Here

2条回答
  •  余生分开走
    2020-12-20 18:16

    We finally figure it out. The problem was simply that we have special characters in our password which break out the url.

    Here is the working code:

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

提交回复
热议问题