我查看了为什么 Jenkins 在从 git 获取数据时失败,而命令行则不然?、Jenkins 在结帐时失败以及各种其他搜索结果。
在一个 Jenkins 节点上,bitbucket.org 存储库的签出失败。在其他几个节点上,完全相同的结帐成功。这些节点连接到同一个 Jenkins 控制器。 x-auth-token 存储在控制器上的凭证管理器中。
hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- https://bitbucket.org/company/reponame.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
我将
GIT_TRACE=1
添加到环境中以获得一些额外的日志记录。
Started by user User name
Running as SYSTEM
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - Injecting as environment variables the properties content
GIT_TRACE=1
[EnvInject] - Variables injected successfully.
[EnvInject] - Injecting contributions.
Building remotely on company-dev02 (developmenthost linuxreleasehost linux latest22_linux_db test22cloud_linux_db test22_linux_db develop23_linux_db develop_linux_db) in workspace /var/lib/jenkins/workspace/cceadm appltest22/xcomp checkout company-dev02
[EnvInject] - Unset unresolved 'BASH_FUNC_which%%' variable.
The recommended git tool is: NONE
using credential tokentokenTOKENTOKEN
Cloning the remote Git repository
Cloning repository https://bitbucket.org/company/reponame.git
> git init /var/lib/jenkins/workspace/cceadm appltest22/xcomp checkout company-dev02 # timeout=10
Fetching upstream changes from https://bitbucket.org/company/reponame.git
> git --version # timeout=10
> git --version # 'git version 2.31.1'
using GIT_ASKPASS to set credentials token TOKENTOKEN
> git fetch --tags --force --progress -- https://bitbucket.org/company/reponame.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://bitbucket.org/company/reponame.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
Avoid second fetch
> git rev-parse refs/remotes/origin/xcomp/22.0/test^{commit} # timeout=10
> git rev-parse xcomp/22.0/test^{commit} # timeout=10
Checking out Revision e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84 (refs/remotes/origin/xcomp/22.0/test)
> git config core.sparsecheckout # timeout=10
> git checkout -f e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84 # timeout=10
Commit message: "Merge branch 'user/config/company-812-Cloud-build' into xcomp/22.0/test"
> git rev-list --no-walk e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84 # timeout=10
18:51:17.933383 git.c:447 trace: built-in: git whatchanged --no-abbrev -M '--format=commit %H%ntree %T%nparent %P%nauthor %aN <%aE> %ai%ncommitter %cN <%cE> %ci%n%n%w(0,4,4)%B' -n 1024 e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84 ^e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84
The recommended git tool is: NONE
using credential tokentokenTOKENTOKEN
> git rev-parse e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84^{commit} # timeout=10
The recommended git tool is: NONE
using credential tokentokenTOKENTOKEN
[GitCheckoutListener] Recording commits of 'git https://bitbucket.org/company/reponame.git'
[GitCheckoutListener] Found previous build 'cceadm appltest22/xcomp checkout company-dev02 #2' that contains recorded Git commits
[GitCheckoutListener] -> Starting recording of new commits since 'e7ce93e'
[GitCheckoutListener] -> Multiple parent commits found - storing latest commit of local merge 'e7ce93e'
[GitCheckoutListener] -> Using parent commit '05cef30' of local merge as starting point
[GitCheckoutListener] -> Storing target branch head '74f329b' (second parent of local merge)
[GitCheckoutListener] -> Recorded 200 new commits
[GitCheckoutListener] -> The latest commit 'e7ce93ef07cdaff3ae372dfed57c93ccf3ebbd84' is a merge commit
[GitCheckoutListener] -> Git commit decorator successfully obtained 'hudson.plugins.git.browser.BitbucketWeb@72f603c0' to render commit links
Finished: SUCCESS
Started by user User name
Running as SYSTEM
[EnvInject] - Loading node environment variables.
[EnvInject] - Preparing an environment for the build.
[EnvInject] - Keeping Jenkins system variables.
[EnvInject] - Keeping Jenkins build variables.
[EnvInject] - Injecting as environment variables the properties content
GIT_TRACE=1
[EnvInject] - Variables injected successfully.
[EnvInject] - Injecting contributions.
Building remotely on company-admdb (applprod22_linux_db linux appltest22_linux_db) in workspace /var/lib/jenkins/workspace/cceadm appltest22/xcomp checkout
[EnvInject] - Unset unresolved 'BASH_FUNC_which%%' variable.
The recommended git tool is: NONE
using credential tokentokenTOKENTOKEN
Cloning the remote Git repository
Cloning repository https://bitbucket.org/company/reponame.git
> git init /var/lib/jenkins/workspace/cceadm appltest22/xcomp checkout # timeout=10
Fetching upstream changes from https://bitbucket.org/company/reponame.git
> git --version # timeout=10
> git --version # 'git version 2.31.1'
using GIT_ASKPASS to set credentials token TOKENTOKEN
> git fetch --tags --force --progress -- https://bitbucket.org/company/reponame.git +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- https://bitbucket.org/company/reponame.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: 18:54:05.328181 git.c:447 trace: built-in: git fetch --tags --force --progress -- https://bitbucket.org/company/reponame.git '+refs/heads/*:refs/remotes/origin/*'
18:54:05.328405 run-command.c:667 trace: run_command: GIT_DIR=.git git remote-https https://bitbucket.org/company/reponame.git https://x-token-auth:*******************************************************************************************@bitbucket.org/company/reponame.git
18:54:05.330301 git.c:733 trace: exec: git-remote-https https://bitbucket.org/company/reponame.git https://x-token-auth:*******************************************************************************************@bitbucket.org/company/reponame.git
18:54:05.330335 run-command.c:667 trace: run_command: git-remote-https https://bitbucket.org/company/reponame.git https://x-token-auth:*******************************************************************************************@bitbucket.org/company/reponame.git
remote: The requested repository either does not exist or you do not have access. If you believe this repository exists and you have access, make sure you're authenticated.
fatal: unable to access 'https://bitbucket.org/company/reponame.git/': The requested URL returned error: 403
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2842)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2185)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:635)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:871)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:170)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$GitCommandMasterToSlaveCallable.call(RemoteGitImpl.java:161)
at hudson.remoting.UserRequest.perform(UserRequest.java:211)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request$2.run(Request.java:377)
at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Suppressed: hudson.remoting.Channel$CallSiteStackTrace: Remote call to company-admdb
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1787)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
at hudson.remoting.Channel.call(Channel.java:1003)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.execute(RemoteGitImpl.java:153)
at jdk.internal.reflect.GeneratedMethodAccessor2090.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler.invoke(RemoteGitImpl.java:138)
at jdk.proxy123/jdk.proxy123.$Proxy256.execute(Unknown Source)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1222)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1305)
at hudson.scm.SCM.checkout(SCM.java:540)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1248)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:521)
at hudson.model.Run.execute(Run.java:1895)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE
我发现了问题。我不知道有人会遇到这个问题的相同原因的可能性有多大,但无论如何我都会发布解决方案。
在过去的某个时刻,
git config insteadof
是为运行 jenkins 代理的用户设置的,请参阅如何将 `git:` url 转换为 `http:` url。
添加它是为了在幕后插入令牌身份验证,使用
git config --global url."https://x-token-auth:[email protected]".insteadOf https://bitbucket.org
那里使用的令牌对某些存储库有效,但不适用于所有存储库。
使用
git config --global -e
删除配置解决了问题。
感谢@jim-redmond 的评论为我指明了正确的方向。