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.
fatal: could not read Username for 'https://<repo>': Device not configured
Is there an existing step that can be used either to tag a repo or to get round the credentials problem?
So I tried the solution of @user3617723 but from some reason something was missing. after a while I found my issue. I have an upper job which responsible to pull the git repo and trigger the pipeline job with my workflow script which has different workspace:
I've managed to get this working by using the
withCredentials
step provided by the credentials binding plugin.Its not great because it involved specifying it all in the URL but these values are masked in the console output.
If your git password contains special characters such as "%", ":", "@", or "/", passing
${env.GIT_PASSWORD}
as part of the git url iehttps://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@<REPO>
without doing any encoding is likely to result in anInvalid username or password
error.To save any hassle using an inline credential.helper is a better way to go however the suggestion of
!echo password=\$GIT_PASSWORD; echo'
will result in a warning in your build logswarning: invalid credential line: get
as the credential.helper is passed an argument to indicate the required operation (get,store,erase). In this case the credential helper is trying to interpret theget
operation as a credential input. Valid inputs are protocol,host,path,username,password,url. See https://git-scm.com/docs/git-credential#IOFMTA better inline credential.helper would be
!f() { echo password=\$GIT_PASSWORD; }; f
This way the credential.helper operationget
is ignored.Full example:
You can create your own personal API token (OAuth) and use it the same way as you would use your normal credentials (at:
/settings/tokens
). For example:Here's an alternative that does not require knowing the URL of the remote:
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.The following works for me
I guess that it depends how the checkout is configured and if it somehow keeps the git credentials configured for the rest of the script.