詹金斯(Jenkins)的Git Clone和个人访问令牌永远闲置

时间:2019-06-28 15:36:54

标签: git jenkins

我们有一个企业github运行在公司网络外部的远程github服务器上,需要使用https代理进行克隆。我们不允许使用密码身份验证,因此无论是ssh(由于代理问题而不能使用)还是PAT。

在我的命令行上,命令

git clone https://user:token@github.exampleco.com/org/repo.git

克隆存储库没有问题,大约需要5到10秒。

在Jenkins中,控制台输出显示“正在克隆到目录名”,然后有一个旋转的纺纱轮不断旋转,而这种旋转永远无法解决。

我正在执行shell脚本中运行此脚本,因为github插件运行了一些显然仍要进行密码身份验证的命令,即使我在没有凭据的情况下提供了URL的PAT版本,也看不到添加凭据模式中的PAT授权选项。

要澄清提供给Jenkins插件的网址,是:

https://user:token@github.exampleco.com/org/repo.git

我得到这样的输出:

No credentials specified
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://user:token@github.exampleco.com/org/repo.git # timeout=10
Fetching upstream changes from https://user@github.exampleco.com/org/repo.git
 > git --version # timeout=10
Setting http proxy: corporateproxy.com:8080
 > git fetch --tags --progress https://user@github.exampleco.com/org/repo.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://user@github.exampleco.com/org/repo.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:894)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1161)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1192)
    at hudson.scm.SCM.checkout(SCM.java:504)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1208)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:574)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:499)
    at hudson.model.Run.execute(Run.java:1818)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://user@github.exampleco.com/org/repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: remote: Password authentication is not available for Git operations.
remote: You must use a personal access token or SSH key.
remote: See https://github.exampleco.com/settings/tokens or https://github.exampleco.com/settings/ssh
fatal: unable to access 'https://user@github.exampleco.com/org/repo.git': The requested URL returned error: 403

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2042)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1761)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$400(CliGitAPIImpl.java:72)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:442)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:892)
    ... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE

我确实注意到,在配置远程源之后,删除了user:token @,而只使用了user @。我尝试在外壳中手动运行所有这些命令,当我进入第二个命令时,即:

git fetch --tags --progress https://user:token@github.exampleco.com/org/repo.git

它也像克隆命令一样永远闲置。

2 个答案:

答案 0 :(得分:2)

我找到了一个更简单的选择,

请参考此答案 https://stackoverflow.com/a/61104238/5108695


经过大量的搜索后,我找到了答案,事实证明,这比我想起来容易得多

显然,就詹金斯而言,至少可以将个人访问令牌用作密码。我向凭证管理器添加了新凭证,选择了“用户名和密码”类型,输入了不存在的用户名(“ user”),并将个人访问令牌输入了密码字段。

这样,我可以像以前一样从下拉列表中选择凭据,并且项目被克隆而没有问题


答案 1 :(得分:0)

问题是我需要自己而不是詹金斯跑步。以用户jenkins身份运行不允许我们克隆。

我们可以通过将命令whoami放入执行外壳构建步骤来检查谁在运行。如果您的whoami与您的用户名不匹配(whoami很可能会返回詹金斯作为用户名),则我们需要进行一些配置。

转到jenkins主页,选择“管理Jenkins”,然后选择“管理节点”。创建一个新节点。

给该新节点一个执行者,在使用中选择“仅使用具有与此节点匹配的标签表达式的作业”,并为您的项目提供唯一的标签。在启动方法中选择“通过SSH启动代理”。将主机设置为localhost,然后添加您的凭据(用户名和密码)以登录到您使用的计算机。选择不验证主机密钥,然后在可用性中选择“使该代理尽可能联机”并保存。您需要启动代理。

现在去上班。在“常规”选项卡中的“配置”下,选中“限制此作业的运行位置”,然后输入该唯一标签。保存。现在,您的工作应该以与命令行git完全相同的方式克隆。

这在Mac(不支持Windows)上可以运行,但我认为它基本相同。

相关问题