Home > Back-end >  Jenkins Pipeline - how not to exit on error?
Jenkins Pipeline - how not to exit on error?

Time:11-24

I'm new to Jenkins and I wrote a Pipeline with the following code:

build job: 'Dummy_Test',
            parameters:[
                        [$class: 'StringParameterValue', name: 'TEST_EVENT_NAME', value: 'integrated test' ],
                        [$class: 'StringParameterValue', name: 'TEST_TEAM', value: 'testing' ],
                        [$class: 'StringParameterValue', name: 'TEST_INDEX', value: '1' ],
                       ]
build job: 'Dummy_Test',
            parameters:[
                        [$class: 'StringParameterValue', name: 'TEST_EVENT_NAME', value: 'test feature 1' ],
                        [$class: 'StringParameterValue', name: 'TEST_TEAM', value: 'testing' ],
                        [$class: 'StringParameterValue', name: 'TEST_INDEX', value: '2' ],
                       ]
build job: 'Dummy_Test',
            parameters:[
                        [$class: 'StringParameterValue', name: 'TEST_EVENT_NAME', value: 'feature 1' ],
                        [$class: 'StringParameterValue', name: 'TEST_TEAM', value: 'dev' ],
                        [$class: 'StringParameterValue', name: 'TEST_INDEX', value: '1' ],
                       ]
build job: 'Dummy_Test',
            parameters:[
                        [$class: 'StringParameterValue', name: 'TEST_EVENT_NAME', value: 'fix bug' ],
                        [$class: 'StringParameterValue', name: 'TEST_TEAM', value: 'dev' ],
                        [$class: 'StringParameterValue', name: 'TEST_INDEX', value: '2' ],
                       ]

This Pipeline builds job Dummy_Test with different parameters, one after another.

If a job build fails, the job defined after that job in the Pipeline will not run.

How do I change this behavior and make Jenkins continue executing the Pipeline?

CodePudding user response:

You are probably looking for the catchError built-in, which acts as a try-catch block and continues the script. You would simply wrap each of your build job: statements with it.

Note that it will set the build status to FAILURE, if any of the jobs fail, even though it won't halt the script.

  • Related