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
You can't use username:password for connecting to git repo in script.
You should use ssh key. Please see this answer for more information
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'
}