致命错误:无法读取用户名,没有这样的设备。

26

在我的Jenkins任务中,我正在以下列方式配置git:

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")

然而,当我尝试向我的仓库推送时,在最后一行,我会遇到关于仓库的以下错误:

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

有什么问题,如何将其推送到代码库?


1
你尝试过使用--global吗?试试这个:git config --global user.name "my-user-name" - aicastell
1
这与你的 Git user.email/user.name 无关,而是与你的 用户名/密码 进行身份验证有关。 - Sajib Khan
这个回答解决了你的问题吗?GitHub - fatal: could not read Username for 'https://github.com': No such file or directory - محمد جعفر نعمة
1个回答

13

你正在寻找 credential.username。我不知道密语,但如果你不喜欢 http://username:password@my-git-repo.com:8000,那么就像这样将凭证放在你的 Jenkinsfile 中:

第二常见的凭证类型是“用户名和密码”,仍然可以在 environment 指令中使用,但会导致设置稍有不同的变量。

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

这将实际设置3个环境变量:

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

credentials 仅适用于 Declarative Pipeline。对于使用 Scripted Pipeline 的用户,请参阅 withCredentials 步骤的文档。


3
这真的是救命稻草。使用环境凭据和命令“git remote set-url origin "https://$<ACCESS_VAR>@<GIT_REPO_URL>"”终于让git push工作了,在所有其他涉及withCredentials的解决方案失败后。 - MK10
谢谢。虽然是一种变通方法,但在几天后它救了我。 - Kulight

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接