DenCowboy
DenCowboy

Reputation: 15106

Trigger jenkins pipeline B after jenkins pipeline A finished succesfuly

I'm using jenkins declarative syntax. I want to trigger job B after job A succeeds and provide some parameters. This seems to work for me but job A remains running till job B is finished instead that job A finishes and job B starts:

Job A

pipeline {
    agent any


    options {
        buildDiscarder(logRotator(numToKeepStr: '3'))
    }

    parameters {
        string(defaultValue: 'MAJOR.MINOR.PATCH', description: 'Version of Maven X.X.X-SNAPSHOT (+ Version of Support Branch)', name: 'VERSION')
    }

    stages {
        stage('print') {
            steps {
                script {
                    echo env.VERSION
                }
            }
        }
    }

    post {
        always {
            cleanWs()
        }

        success {
            echo "hey"  
            build job: 'debug/job2', parameters: [[$class: 'StringParameterValue', name: 'PARAM', value: env.VERSION]]
        }
    }
}

Job B

pipeline {
    agent any


    options {
        buildDiscarder(logRotator(numToKeepStr: '3'))
    }

    parameters {
        string(defaultValue: 'MAJOR.MINOR.PATCH', description: 'Version of Maven X.X.X-SNAPSHOT (+ Version of Support Branch)', name: 'PARAM')
    }

    stages {
        stage('print') {
            steps {
                script {
                    echo env.TEST
                }
            }
        }
    }

}

one issue

Upvotes: 0

Views: 234

Answers (1)

Sam
Sam

Reputation: 2882

See the documentation for the build step here: https://jenkins.io/doc/pipeline/steps/pipeline-build-step/

You can use the wait property

build job: 'debug/job2', parameters: [[$class: 'StringParameterValue', name: 'PARAM', value: env.VERSION]], wait: false

Upvotes: 2

Related Questions