26

In my Jenkins job, I am configuring git in the following way:

sh("git config user.email my.email@google.com")
sh("git config user.name my-user-name")
sh("git tag ${BUILD_NUMBER}")
sh("git push origin --tags")

However, on the last line, when I try to push to my repository, I get the following error about the repository:

fatal: could not read Username for 'http://my-git-repo.com:8000': No such device or address

What's wrong and how can I make it push to the repository?

Eel Lee
  • 3,513
  • 2
  • 31
  • 49
bsky
  • 19,326
  • 49
  • 155
  • 270
  • 1
    Have you tryied using --global? Try this: git config --global user.name "my-user-name" – aicastell Mar 03 '17 at 10:55
  • 1
    it's not your git `user.emai/user.name`, It's your `username/password` for authentication. – Sajib Khan Mar 03 '17 at 11:01
  • Does this answer your question? [GitHub - fatal: could not read Username for 'https://github.com': No such file or directory](https://stackoverflow.com/questions/22147574/github-fatal-could-not-read-username-for-https-github-com-no-such-file-o) – محمد جعفر نعمة Oct 15 '22 at 02:21

1 Answers1

13

You're looking for credential.username. I don't know about the passphrase, but if you dislike http://username:password@my-git-repo.com:8000 then put the credentials in your Jenkinsfile like so:

The second most common type of Credentials is "Username and Password" which can still be used in the environment directive, but results in slightly different variables being set.

environment {
   SAUCE_ACCESS = credentials('sauce-lab-dev')
}

This will actually set 3 environment variables:

SAUCE_ACCESS containing <username>:<password>
SAUCE_ACCESS_USR containing the username
SAUCE_ACCESS_PSW containing the password

credentials is only available for Declarative Pipeline. For those using Scripted Pipeline, see the documentation for the withCredentials step.

Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124
  • 3
    This was a lifesaver. Using the environment credentials along with the command 'git remote set-url origin "https://$@"' finally got git push working, after all the other solutions involving withCredentials failed. – MK10 Nov 05 '18 at 19:02
  • Thank you. Although a workaround, It saved me after a couple of day. – Kulight Feb 24 '20 at 12:01