在并行管道脚本Jenkins中运行作业

时间:2019-04-30 07:06:36

标签: jenkins jenkins-pipeline

我编写了下面的代码以按流水线脚本Jenkins顺序执行作业,但是我要求从下面并行运行“ build”和“ Undeploy”,然后在此之后“ Deploy”

node: {
  stage 'build'
  build job: 'JenkinsTest', parameters: [
    [$class: 'StringParameterValue', name: 'VERSION', value: "${VERSION}"],
    [$class: 'StringParameterValue', name: 'RBFLAG', value: "${RBFLAG}"],
    [$class: 'StringParameterValue', name: 'SET_ENV', value: "${SET_ENV}"]
    ]

stage 'Undeploy'
build job:  'Undeploy job', parameters: [
    [$class: 'StringParameterValue', name: 'RBFLAG', value: "${RBFLAG}"]
    ]

stage 'Deploy'
build job:  'Deploy job', parameters: [
    [$class: 'StringParameterValue', name: 'RBFLAG', value: "${RBFLAG}"]
    ]
}

请帮助。

1 个答案:

答案 0 :(得分:1)

尝试使用以下类似内容,并使用以下命令:1

pipeline {
agent any   
stages {
    stage('First Stage'){
        steps{
            script{
                parallel(
                        "build":{
                            build job: 'JenkinsTest', parameters: [
                                [$class: 'StringParameterValue', name: 'VERSION', value: "${VERSION}"],
                                [$class: 'StringParameterValue', name: 'RBFLAG', value: "${RBFLAG}"],
                                [$class: 'StringParameterValue', name: 'SET_ENV', value: "${SET_ENV}"]
                                ]
                        },
                        "undeploy":{
                           build job:  'Undeploy job', parameters: [
                            [$class: 'StringParameterValue', name: 'RBFLAG', value: "${RBFLAG}"]
                            ]
                        }
                )
            }
        }
    }
    stage('Second stage') {
        steps{
            script{
                build job:  'Deploy job', parameters: [
                    [$class: 'StringParameterValue', name: 'RBFLAG', value: "${RBFLAG}"]
                    ]
                }
            }
    }
}

}