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

时间:2018-11-30 10:26:47

标签: jenkins jenkins-pipeline

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

在配置中,我添加了一个git参数“ branch”,如下所示: enter image description here

然后,我在管道定义中将“ branch”参数添加为分支指定符,如下所示: enter image description here

开始构建时,可以毫无问题地选择分支。在此示例中,/ 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#超时= 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}#timeout = 10

     

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

因此,詹金斯(Jenkins)找不到分支/ origin / feature / kvarntorp-test1,因为他正在搜索/ origin / feature / kvarntorp-test1 ^ {commit}

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

我尝试使用其他名称代替“ branch”。 Git PullRequest job failed. Couldn't find any revision to build. Verify the repository and branch configuration for this job建议我将sha1与默认值“ master”一起使用。我尝试将sha1作为Git参数名称,将$ {sha1}作为Branch Specifier。构建失败,并显示以下控制台输出:

hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/${sha1}:refs/remotes/origin/${sha1} --prune" returned status code 128:
stdout: 
stderr: fatal: Couldn't find remote ref refs/heads/${sha1}
fatal: The remote end hung up unexpectedly

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

2 个答案:

答案 0 :(得分:0)

摘自SCM/Branches to build's手册:

  

如果您要跟踪广告中的特定分支,请指定分支   资料库。如果留空,将检查所有分支的更改   并建成。

     

最安全的方法是使用refs / heads /语法。这条路   预期的分支是明确的。

     

如果您的分支名称中包含/,请确保使用完整引用   以上。如果未提供完整路径,则插件将仅使用   最后一个斜杠的字符串部分。含义foo / bar将   实际匹配栏   如果您使用带有斜杠(例如release /)的通配符分支说明符,   您需要在分支名称中指定原始存储库以   确保选择了更改。所以例如起源/发行/

     

可能的选项:

     

跟踪/签出指定的分支。如果模棱两可   取得第一个结果,不一定是预期的结果。   最好使用refs / heads /。例如。主人,feature1,...

所以尝试refs / heads / $ {branch}

答案 1 :(得分:0)

我知道了。这是两件事的结合。 首先,我不得不取消选中Jenkins Git Branch not working with Environment Variables中所述的“轻量级结帐”。

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

相关问题