Subrat Sahoo
Subrat Sahoo

Reputation: 195

How to add a post build action in the pipeline in Jenkins

Below is my pipeline script

node(Slave01) {
currentBuild.displayName = "${URL_Name}"
}
stage 'Pt2ctf process'
node(Slave01) {
build job: 'Pt2ctf_16_7', parameters: [string(name: 'URL_Name', value: "${URL_name}"), string(name: 'Display_Name', value: "${Display_Name}")]
}
stage 'add_fields'
node(Slave01) {
build job: 'add_fields_16_7', parameters: [string(name: 'URL_Name', value: "${URL_Name}")]
}

The above groovy script would trigger multiple builds in sequence. I have another build to be run once the sequence is completed. I don't see any post build option in the pipeline job configuration.

Is it possible that we can add few more lines like below:

post
node(Slave01){
build job: 'testing_build'
}

Or do we have any other option? please suggest

Upvotes: 10

Views: 65906

Answers (2)

Olia
Olia

Reputation: 811

You can simply add post action to your pipeline script, in case of using declarative pipeline. It is explained in Pipeline syntax reference.

Upvotes: 6

vsbehere
vsbehere

Reputation: 666

You can add a stage for post build to add post build action in pipeline:

stage 'post-build'
node(Slave01){
build job: 'testing_build'
}

You can use this stage as:

try {
    //Stages to be included in build
    ...
} catch {
    ...
} finally {
    stage 'post-build'
    ...
}

Upvotes: 4

Related Questions