简体   繁体   中英

Run jobs in parallel Pipeline script Jenkins

I wrote below code to execute jobs in sequence in Pipeline script Jenkins, but I have a requirement to run 'build' and 'Undeploy' from below as parallel and then 'Deploy' after that

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}"]
    ]
}

Please help.

Give it a try with something like below, using parallel: 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}"]
                    ]
                }
            }
    }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM