Jenkins 参数化构建:由于 git 参数包含 {^commit},构建失败

Mar*_*son 3 jenkins jenkins-pipeline

我想设置一个参数化构建,以便用户可以选择分支,然后按“构建”来构建该分支。

在配置中我添加了一个 git 参数“branch”,如下所示: 在此输入图像描述

然后,我在管道定义中添加了“branch”参数作为分支说明符,如下所示: 在此输入图像描述

当我开始构建时,我可以毫无问题地选择分支。在此示例中 /origin/feature/kvarntorp-test1。但构建将失败并显示以下控制台输出:

由用户 xxxx 启动 轻量级结帐支持不可用,退回到完整结帐。将 git ssh://gitolite@tuleap.ermms.se/ermms/acm.git 检出到 /var/lib/jenkins/workspace/6smCustomBuild@script 以读取 ci/jenkins/6msBuildAndTest.groovy

> git rev-parse --is-inside-work-tree # timeout=10 从远程 Git 存储库获取更改
> git config remote.origin.url ssh://gitolite@tuleap.ermms.se/ermms/acm.git # timeout=10 从 ssh://gitolite@tuleap.ermms.se/ermms/acm.git 获取上游更改
> git --version # timeout=10 使用 GIT_SSH 设置凭据
> git fetch --tags --progress ssh: //gitolite@tuleap.ermms.se/ermms/acm.git +refs/heads/ :refs/remotes/origin/
> git rev-parse /origin/feature/kvarntorp-test1^{commit} # timeout=10
> git rev-parse refs/remotes/origin //origin/feature/kvarntorp-test1^{commit} # 超时=10
> git rev-parse /origin/feature/kvarntorp-test1^{commit} # 超时=10

错误:找不到任何要构建的修订版本。验证此作业的存储库和分支配置。
错误:已达到最大结帐重试尝试次数,正在中止已完成:失败

所以Jenkins找不到分支/origin/feature/kvarntorp-test1,因为他正在搜索/origin/feature/kvarntorp-test1^{commit}

^{commit} 从哪里来?我可以以某种方式删除构建配置中的 ^{commit} 吗?我是否配置了错误的构建?

我尝试过不同的名称而不是“分支”。Git PullRequest 作业失败。找不到任何要构建的修订版。验证此作业的存储库和分支配置建议我应该使用 sha1 和默认值“master”。我尝试使用 sha1 作为 Git 参数名称,使用 ${sha1} 作为分支说明符。构建失败并显示以下控制台输出:

hudson.plugins.git.GitException:命令“git fetch --tags --progress origin +refs/heads/${sha1}:refs/remotes/origin/${sha1} --prune”返回状态代码 128:
标准输出:
stderr:致命:找不到远程引用 refs/heads/${sha1}
fatal:远端意外挂断

    在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2002)
    在org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1721)
    在org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:72)
    在 org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:405)
    在 jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:351)
    在 jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:196)
    在 jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:172)
    在 org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:108)
    在 org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
    在 org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:298)
    在 hudson.model.ResourceController.execute(ResourceController.java:97)
    在 hudson.model.Executor.run(Executor.java:429)
完成:失败

Mar*_*son 5

我成功了。这是两件事的结合。首先,我必须取消选中轻量级签出,如Jenkins Git Branch not work with Environment Variables中所述。

但仅此一点并不能解决问题。我还必须将参数名称设置为 sha1,将分支说明符设置为 ${sha1}。