Git 在 Jenkins 代理中提示输入用户名
Git prompt for username in Jenkins agent
有没有办法将 git 凭据传递给 Jenkins 代理?
我是 Kubernetes 中的 运行 Jenkins,我有一个通过 pod 模板定义的代理来执行特定构建。
我的挑战是构建不断失败并出现此错误 `fatal: could not read Username for 'https://github.com': No such device or address
我已经执行到代理中进行更深入的挖掘,结果发现当在管道中执行 git push
命令时,会提示输入用户名 Username for 'https://github.com':
如何将凭据传递到代理中,以便它在不提示的情况下直接使用它?
我看过这个 https://github.com/github/hub/issues/1644 and tried to configure the credential helper as explained here 但我仍然收到提示。
凭据助手的一个问题似乎是您仍然必须至少输入一次用户名和密码,我不能这样做,因为它是 运行 自动化。
我会选择 ssh,但不幸的是,目前无法选择。
有人有什么想法吗?
通常您需要将您的凭据(GitHub 用户名和令牌)存储在凭据存储中并通过 withCredentials
块使用它们。
withCredentials([usernamePassword(
credentialsId: 'MY_GITHUB_USERNAME_PASSWORD_CREDENTIALS',
passwordVariable: 'TOKEN',
usernameVariable: 'USER')]) {
sh "git push https://${USER}:${TOKEN}@github.com/mycompany/myrepo.git mybranch -f"
}
如果您想使用 SSH Agent plugin,您可以使用 ssh
身份验证而不是 https
。将 public 密钥添加到 GitHub 用户后,这可能如下所示:
sshagent(credentials: ['MY_GITHUB_SSH_CREDENTIALS']) {
sh "git push git@github.com:mycompany/myrepo.git mybranch -f")
}
有没有办法将 git 凭据传递给 Jenkins 代理?
我是 Kubernetes 中的 运行 Jenkins,我有一个通过 pod 模板定义的代理来执行特定构建。
我的挑战是构建不断失败并出现此错误 `fatal: could not read Username for 'https://github.com': No such device or address
我已经执行到代理中进行更深入的挖掘,结果发现当在管道中执行 git push
命令时,会提示输入用户名 Username for 'https://github.com':
如何将凭据传递到代理中,以便它在不提示的情况下直接使用它?
我看过这个 https://github.com/github/hub/issues/1644 and tried to configure the credential helper as explained here 但我仍然收到提示。
凭据助手的一个问题似乎是您仍然必须至少输入一次用户名和密码,我不能这样做,因为它是 运行 自动化。
我会选择 ssh,但不幸的是,目前无法选择。
有人有什么想法吗?
通常您需要将您的凭据(GitHub 用户名和令牌)存储在凭据存储中并通过 withCredentials
块使用它们。
withCredentials([usernamePassword(
credentialsId: 'MY_GITHUB_USERNAME_PASSWORD_CREDENTIALS',
passwordVariable: 'TOKEN',
usernameVariable: 'USER')]) {
sh "git push https://${USER}:${TOKEN}@github.com/mycompany/myrepo.git mybranch -f"
}
如果您想使用 SSH Agent plugin,您可以使用 ssh
身份验证而不是 https
。将 public 密钥添加到 GitHub 用户后,这可能如下所示:
sshagent(credentials: ['MY_GITHUB_SSH_CREDENTIALS']) {
sh "git push git@github.com:mycompany/myrepo.git mybranch -f")
}