Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 966
Subrat Sahoo Avatar asked Apr 05 '17 10:04

Subrat Sahoo


People also ask

What is Post section in Jenkins pipeline?

Since the post section of a Pipeline is guaranteed to run at the end of a Pipeline's execution, we can add some notification or other steps to perform finalization, notification, or other end-of-Pipeline tasks. See Glossary - Build Status for the different build statuses: SUCCESS, UNSTABLE, and FAILED.

What is post action in Jenkins?

Post Actions are just like other normal stages but that running in specific conditions. Jenkins supports 10 special action conditions which are running when these conditions meet. They are related to run status and can be defined in the post block both for the whole pipeline and per-stage.


2 Answers

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

like image 122
Olia Avatar answered Sep 19 '22 14:09

Olia


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'
    ...
}
like image 33
vsbehere Avatar answered Sep 18 '22 14:09

vsbehere