1
votes

I run in a Jenkins pipeline, a series of stages. Each stage represents a test. Even if a stage (test) fails, I'd like to continue with the following stages (tests), but I don't know how.

The only solution I know is to enclose the stage steps with a try/catch clause, but in this way I don't know easily if a test has failed or succeeded.

They cannot run in parallel, they must be run sequentially.

Is there a better solution?

Related question: Jenkins continue pipeline on failed stage

1

1 Answers

1
votes

This isn't optimal, because Jenkins doesn't know which stages have failed, but we collect this data manually:

    def success = 0
    def failed = []

    for (int i = 0; i < tests.size(); i++) {
        def test = tests[i]
        stage(test) {
            try {
                sh "...."
                success++
            } catch (e) {
                failed << test
            }
        }
    }
    stage('Report') {
        def failCount = tests.size()-success
        if (failCount == 0)
            echo "Executed ${success} tests successfully."
        else
            error """Executed ${success} tests successfully and ${failCount} failed:
${failed.join(', ')}"""
    }