1

During our jenkins build we are attempting to push to git. Our password has recently changed, and now includes an @ symbol which gives the following error:

The advice seems to be to encode the password, but I am unable to figure out how to do this within our jenkins pipeline. How do I do this? (I have also tried using the replace method to swap the @ symbol for %40, but that didn't work.)

def GIT_PASSWORD_R = GIT_PASSWORD.replace('@', '%40') 

Escape @ character in git proxy password

def GIT_PASSWORD_R = GIT_PASSWORD.toURL()       
git push -f https://${GIT_USERNAME}:${GIT_PASSWORD_R}@github.company.com/Product/subProd.git ${VERSION}-SNAPSHOT
James Hutchinson
  • 841
  • 2
  • 13
  • 27

1 Answers1

2

I have had the same problem. Rather than encoding, another option that is working for me is to use a git credential helper. See this answer: https://stackoverflow.com/a/40038869/9463800

It sets up a git credential helper, does a git operation, and unsets the password in a finally block.

try {
  withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'MyID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
    sh("${git} config credential.username ${env.GIT_USERNAME}")
    sh("${git} config credential.helper '!echo password=\$GIT_PASSWORD; echo'")
    sh("GIT_ASKPASS=true ${git} push origin --tags")
  }
} finally {
    sh("${git} config --unset credential.username")
    sh("${git} config --unset credential.helper")
}
grantler
  • 216
  • 1
  • 7
  • Welcome to SO. Please update your answer according to hints at https://stackoverflow.com/help/how-to-answer by quoting a bit more from the solution. – B--rian Aug 15 '19 at 13:45