10

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

Eel Lee
  • 3,513
  • 2
  • 31
  • 49
Subrat Sahoo
  • 195
  • 1
  • 3
  • 17
  • Guys can anyone please suggest – Subrat Sahoo Apr 05 '17 at 11:07
  • 2
    possible duplicate of http://stackoverflow.com/questions/36651432/how-to-implement-post-build-stage-using-jenkins-pipeline-plug-in – Tidhar Klein Orbach Apr 05 '17 at 11:40
  • Possible duplicate of [How to implement Post-Build stage using Jenkins Pipeline plug-in?](https://stackoverflow.com/questions/36651432/how-to-implement-post-build-stage-using-jenkins-pipeline-plug-in) – user7610 Feb 16 '18 at 07:01

2 Answers2

6

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Olia
  • 815
  • 4
  • 16
  • 1
    @Vadim Kotov Can you drop me a snippet ? And the other job(example: job2) should run after pipeline completes all builds internally. Nothing should be in parallel. I have tried but i get this error : java.lang.NoSuchMethodError: No such DSL method 'post' found among steps – Subrat Sahoo Jun 09 '17 at 14:28
  • @Vadim Kotov for pipeline: java.lang.NoSuchMethodError: No such DSL method 'pipeline' found I am using ""Pipeline configuration Job" – Subrat Sahoo Jun 09 '17 at 14:39
  • @SubratSahoo, here is a code snippet as well: https://jenkins.io/doc/book/pipeline/syntax/#post. Maybe, you made some syntax mistake that's why you are getting error? – Olia Jun 19 '17 at 13:57
  • i have made the correct steps, but this doesn't support my requirement. When i give post build, it runs for each parameter that i pass. Thanks – Subrat Sahoo Jun 19 '17 at 14:35
4

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'
    ...
}
vsbehere
  • 666
  • 1
  • 7
  • 23
  • 3
    this is not my requirement. I need to add a post-build for the pipeline but not another post build stage post build is to trigger another job outside the pipeline – Subrat Sahoo Jun 09 '17 at 14:30