GERRIT_REFSPEC 在 scm git 结帐期间无法识别 - Jenkinsfile 声明
GERRIT_REFSPEC not recognized during scm git checkout - Jenkinsfile declarative
我有一个使用 kubernetes 代理的声明式管道。
pipeline {
agent {
kubernetes {
yamlFile "file.yml"
}
}
...
}
管道由Gerrit触发器启动,GERRIT_REFSPEC参数由该触发器提供。
在 scm git 校验期间,第一个 git 提取成功(GERRIT_RESPEC 被识别),第二个失败(GERRIT_RESPEC 未被识别)。
Triggered by Gerrit: https://[gerrit-server]
Checking out git ssh://[gerrit-server]/[project] into [workspace] to read Jenkinsfile
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential gerrit
> git rev-parse --resolve-git-dir [workspace]/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url ssh://[gerrit-server]/[project] # timeout=10
Fetching upstream changes from ssh://[gerrit-server]/[project]
> git --version # timeout=10
> git --version # 'git version 2.30.2'
using GIT_SSH to set credentials [gerrit-server]
> git fetch --tags --force --progress -- ssh://[gerrit-server]/[project] refs/changes/11/111111/11:refs/changes/11/111111/11 # timeout=10
> git rev-parse refs/remotes/origin/refs/changes/11/111111/11^{commit} # timeout=10
> git rev-parse refs/changes/11/111111/11^{commit} # timeout=10
Checking out Revision [revision-id] (refs/changes/11/111111/11)
> git config core.sparsecheckout # timeout=10
> git checkout -f [revision-id] # timeout=10
Commit message: "[commit-message]"
First time build. Skipping changelog.
Running in Durability level: MAX_SURVIVABILITY
hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune -- origin +refs/heads/$GERRIT_REFSPEC:refs/remotes/origin/$GERRIT_REFSPEC" returned status code 128:
stdout:
stderr: fatal: couldn't find remote ref refs/heads/$GERRIT_REFSPEC
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2102)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access0(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.execute(CliGitAPIImpl.java:624)
at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:365)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
at org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:101)
at org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:82)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate2(ACL.java:449)
at hudson.security.ACL.impersonate(ACL.java:461)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
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)
Finished: FAILURE
我看到了一些禁用轻量级结帐选项的其他建议,但在我的情况下已经禁用了。
如果我使用节点标签(节点被手动添加到 Jenkins)而不是 kubernetes,scm git 结帐阶段成功。
agent { label [physical-node-label] }
有什么方法可以让 Kubernetes 代理成功完成 scm git 结帐阶段,而无需将管道从声明式更改为脚本式?
使用的版本:
- 詹金斯:2.303.1
- Kubernetes plugin: 1.30.1
- Git plugin: 4.8.2
- Gerrit trigger plugin: 2.34.0
在有效的“git fetch”命令中,使用了以下参数:
refs/changes/11/111111/11:refs/changes/11/111111/11
这等同于:
$GERRIT_REFSPEC:$GERRIT_REFSPEC
执行提取的正确方法是什么。
但是在失败的“git fetch”命令中,使用了以下参数:
refs/heads/$GERRIT_REFSPEC:refs/remotes/origin/$GERRIT_REFSPEC
将替换为:
refs/heads/refs/changes/11/111111/11:refs/remotes/origin/refs/changes/11/111111/11
这是完全错误的。
我不知道为什么会这样:-(
经过多次尝试,我能够通过直接在 groovy 中添加 yaml 内容而不是使用 yamlFile 来“解决”问题。我宁愿把 yaml 放在外面,但由于这个错误,我不得不在里面继续它。
我有一个使用 kubernetes 代理的声明式管道。
pipeline {
agent {
kubernetes {
yamlFile "file.yml"
}
}
...
}
管道由Gerrit触发器启动,GERRIT_REFSPEC参数由该触发器提供。
在 scm git 校验期间,第一个 git 提取成功(GERRIT_RESPEC 被识别),第二个失败(GERRIT_RESPEC 未被识别)。
Triggered by Gerrit: https://[gerrit-server]
Checking out git ssh://[gerrit-server]/[project] into [workspace] to read Jenkinsfile
Selected Git installation does not exist. Using Default
The recommended git tool is: NONE
using credential gerrit
> git rev-parse --resolve-git-dir [workspace]/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url ssh://[gerrit-server]/[project] # timeout=10
Fetching upstream changes from ssh://[gerrit-server]/[project]
> git --version # timeout=10
> git --version # 'git version 2.30.2'
using GIT_SSH to set credentials [gerrit-server]
> git fetch --tags --force --progress -- ssh://[gerrit-server]/[project] refs/changes/11/111111/11:refs/changes/11/111111/11 # timeout=10
> git rev-parse refs/remotes/origin/refs/changes/11/111111/11^{commit} # timeout=10
> git rev-parse refs/changes/11/111111/11^{commit} # timeout=10
Checking out Revision [revision-id] (refs/changes/11/111111/11)
> git config core.sparsecheckout # timeout=10
> git checkout -f [revision-id] # timeout=10
Commit message: "[commit-message]"
First time build. Skipping changelog.
Running in Durability level: MAX_SURVIVABILITY
hudson.plugins.git.GitException: Command "git fetch --tags --force --progress --prune -- origin +refs/heads/$GERRIT_REFSPEC:refs/remotes/origin/$GERRIT_REFSPEC" returned status code 128:
stdout:
stderr: fatal: couldn't find remote ref refs/heads/$GERRIT_REFSPEC
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2102)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access0(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.execute(CliGitAPIImpl.java:624)
at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:365)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
at org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:101)
at org.jenkinsci.plugins.workflow.multibranch.ReadTrustedStep$Execution.run(ReadTrustedStep.java:82)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate2(ACL.java:449)
at hudson.security.ACL.impersonate(ACL.java:461)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
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)
Finished: FAILURE
我看到了一些禁用轻量级结帐选项的其他建议,但在我的情况下已经禁用了。
如果我使用节点标签(节点被手动添加到 Jenkins)而不是 kubernetes,scm git 结帐阶段成功。
agent { label [physical-node-label] }
有什么方法可以让 Kubernetes 代理成功完成 scm git 结帐阶段,而无需将管道从声明式更改为脚本式?
使用的版本:
- 詹金斯:2.303.1
- Kubernetes plugin: 1.30.1
- Git plugin: 4.8.2
- Gerrit trigger plugin: 2.34.0
在有效的“git fetch”命令中,使用了以下参数:
refs/changes/11/111111/11:refs/changes/11/111111/11
这等同于:
$GERRIT_REFSPEC:$GERRIT_REFSPEC
执行提取的正确方法是什么。
但是在失败的“git fetch”命令中,使用了以下参数:
refs/heads/$GERRIT_REFSPEC:refs/remotes/origin/$GERRIT_REFSPEC
将替换为:
refs/heads/refs/changes/11/111111/11:refs/remotes/origin/refs/changes/11/111111/11
这是完全错误的。
我不知道为什么会这样:-(
经过多次尝试,我能够通过直接在 groovy 中添加 yaml 内容而不是使用 yamlFile 来“解决”问题。我宁愿把 yaml 放在外面,但由于这个错误,我不得不在里面继续它。