Reputation: 7022
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
Upvotes: 1
Views: 1356
Reputation: 7022
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(', ')}"""
}
Upvotes: 1