当前位置: 首页 > 面试题库 >

Jenkins中的Git Clone与个人访问令牌永远闲置

尤研
2023-03-14
问题内容

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

在我的命令行上,命令

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

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

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

我正在执行壳脚本中运行此命令,因为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

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


问题答案:

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

通过将命令whoami放入execute shell
build步骤,可以检查正在运行的用户。如果您whoami的用户名不匹配(很可能whoami会返回jenkins作为用户名),我们需要进行一些配置。

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

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

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

这适用于Mac,不确定Windows,但我认为它基本相同。



 类似资料:
  • 问题内容: 我可以通过多种方式提出这个问题,例如如何使用Github个人访问令牌配置Jenkins凭据如何使用Github个人访问令牌在Jenkins中克隆Github存储库 所以这是问题 我知道的替代解决方案 连接 Jenkins中的配置,但我的问题是如何使用以下方法与Github建立Github连接 问题答案: 经过来自Stackoverflow的多个线程的多次讨论之后 我发现一个有用的线程。

  • 我有一个npm包,它依赖于package.json中的私有github服务器中的回购: github服务器使用个人访问令牌(在身份验证期间用作密码)进行安全保护。在本地构建中,用户可以为https://private.github.example.com存储其,git将在npm构建期间自动使用它们访问github存储库。 我在Jenkins中也有一个技术用户,它通常可以通过个人访问令牌访问gith

  • 我知道之前有人对此提出过疑问,但在尝试推送存储库时,我仍然会遇到一个恼人的错误: 在我输入我的个人访问令牌后,它会出错: 远程:2021 8月13日取消了对密码验证的支持。请使用个人访问令牌。遥控器:请看https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/了解更多信息。致命:身份验证

  • 编辑:我刚刚发现它在这里得到了回答:持久的FB访问-服务器拉FB页面信息的令牌

  • 我不熟悉,它代表。我混淆了它的两个术语:访问令牌和刷新令牌。 用户注册/登录站点后,我创建和。 将刷新标记保存在数据库或cookie中。 15分钟后,用户标记访问令牌过期。 如果用户空闲2小时,我将从cookie或DB中删除刷新令牌,否则我将使用刷新令牌续订访问令牌。 有什么优化的方法可以达到这个目的吗?

  • 我想要一些关于如何在隐式授予流中使用ID令牌和访问令牌的澄清。我有一个使用msal.js for Angular包的Angular SPA和一个Web API。API不调用任何外部服务,如MSFT Graph。后端仅使用JWT中的角色声明来建立对API功能的RBAC授权。 这个文档写着:https://docs.microsoft.com/en-us/azure/active-directory/