I\'m currently trying to tag a repo from a Jenkins Workflow script. I\'ve tried using a sh step but this runs into problems because of credentials not being set
Here's an alternative that does not require knowing the URL of the remote:
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")
}
This works by having git read the username from the config, and let the credential helper supply the password only. The extra echo at the end is for making the command that git passes as an argument to the helper not end up on the same line as the password.