代码之家  ›  专栏  ›  技术社区  ›  Geist

Jenkins:获取管道内触发的作业的内部版本号

  •  7
  • Geist  · 技术社区  · 6 年前

    我有一个管道,在一个阶段中运行另一组作业:

    node{
     stage("building_other_components") {
      build 'job1' 
      build 'job2' }}
    

    如何恢复这些作业的内部版本号或URL?我只想通过邮件发送URL(示例: http://localhost:8080/job/job1/25 / 上次更改/ ,我将添加 上次更改 零件)
    谢谢

    2 回复  |  直到 6 年前
        1
  •  9
  •   mkobit    6 年前

    只要等待运行完成(默认值 true ),您可以从 build 步返回值的类型为 org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper ( Javadoc ,则, source code )。您可以查看 建筑 逐步使用 snippet generator

    以部分代码为例:

    final job1Result = build('job1')
    echo "Job 1 number: ${job1Result.number}"
    final job2Result = build('job2')
    echo "Job 2 number: ${job2Result.number}"
    

    这使用 getNumber() 方法获取执行的运行数。

        2
  •  3
  •   Geist    6 年前

    如果对某人有用:

    def job1_props = build 'job1'
    def j1EnvVariables = job1_props.getBuildVariables();
    print "${j1EnvVariables}" 
    

    在j1EnvVariables中,存在环境变量BUILD URL:BUILD\u URL: http://localhost:8080/job/job1/26/ BUILD\u编号:26和其他有用信息 要访问:

    def path1 =" ${j1EnvVariables1.BUILD_URL}last-changes/"