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

oct*_*ian 16 git jenkins

在我的 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")
Run Code Online (Sandbox Code Playgroud)

但是,在最后一行,当我尝试推送到我的存储库时,我收到有关存储库的以下错误:

fatal: could not read Username for 'http://my-git-repo.com:8000': No such device or address
Run Code Online (Sandbox Code Playgroud)

出了什么问题,如何将其推送到存储库?

Cee*_*man 6

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')
}
Run Code Online (Sandbox Code Playgroud)

This will actually set 3 environment variables:

SAUCE_ACCESS containing <username>:<password>
SAUCE_ACCESS_USR containing the username
SAUCE_ACCESS_PSW containing the password
Run Code Online (Sandbox Code Playgroud)

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

  • 这是救命稻草。在所有其他涉及 withCredentials 的解决方案失败后,使用环境凭据以及命令“git remote set-url origin "https://$&lt;ACCESS_VAR&gt;@&lt;GIT_REPO_URL&gt;"”最终使 git push 工作。 (3认同)