jenkins 在pipeline job内调度其他job,并获取job状态

背景:

项目分为前端和后端,先前端发布和后端发布分别有两条流水线: backend和frontend。现需要新建一条流水线并发执行job,并运行api测试用例

流水线如下:

pipeline {
    
  agent {label "master"}
  
  stages {
    stage('部署'){  
      parallel {                   // 并发执行前端和后端发布
        stage('frontend') {
          steps{
            script{
            // 使用build调度前端job,并传参,将结果赋值给frontendBuild
              def frontendBuild=build(job: 'frontend', parameters: [gitParameter(name: 'Branch', value: '*/develop')])       
              println frontendBuild.getProjectName()
              println frontendBuild.getNumber()
              println frontendBuild.getBuildVariables()     // 
              println frontendBuild.buildVariables.image_tag
            }
          }
        }
        
        stage('backend') {
          steps{
             script{ 
              def backendBuild=build(job: 'backend', parameters: [gitParameter(name: 'Branch', value: '*/dev')])
              println backendBuild.getProjectName()
             }
          } 
        }
      }
    }
    
    // stage("测试") {
    //     steps {
    //       sh """echo ${JOB_NAME}"""
    //       sh """echo ${currentBuild.getBuildCauses}"""
    //     }
    // }
  }
  
  post{
      always{        
        script{
           // echo ${currentBuild.result}
           CAUSE = "${currentBuild.getBuildCauses()}"
           // sh """echo ${currentBuild.getBuildCauses()}"""
        }
      }
  }
}

这里有几点需要着重讲解 :

1、

 

上一篇:整数除法verilog代码支持pipeline


下一篇:Apache Beam入门及Java SDK开发初体验