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

若如初见. 提交于 2019-12-09 11:00:57

问题


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


回答1:


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




回答2:


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'
    ...
}


来源:https://stackoverflow.com/questions/43227997/how-to-add-a-post-build-action-in-the-pipeline-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!