Jenkins setup:
Jenkins: 2.426.3
OS: Linux - 4.18.0-193.1.2.el8_2.x86_64
Java: 11.0.13 - Red Hat, Inc. (OpenJDK 64-Bit Server VM)
I’d like one cell (with multiple stages) in a matrix to be special and not cause the main job to fail if a stage within the cell fails. There’s information about using try/catch blocks and catchError options to do this for a single stage but not for multiple stages. Apparently the try/catch block is a script and can only contain steps so after a lot of message around I ended up with this structure:
stage("Matrix build") {
matrix {
axes {
axis {
name "BUILD_VERSION"
values "a", "b", "c", "d"
}
}
stages {
stage("Exception catcher") {
steps {
script {
try {
stage("Primary matrix stage") {
stages {
stage("A") {
steps {
sh """
echo Hello
"""
}
}
stage("B") {
when {
expression {
env.some_condition == "true"
}
}
steps {
sh """
echo Hello
"""
}
}
}
}
}
catch (e) {
if (env.BUILD_VERSION == "c") {
echo "Ignoring exception in matrix cell for config `${env.BUILD_VERSION}': ${e.message}"
} else {
throw e
}
}
}
}
However, I get an error message like so, which appears to be from the stages
inside the try block:
2025-03-31 14:36:00 | java.lang.NoSuchMethodError: No such DSL method 'stages' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, ...
Is it even possible to cover multiple stages with a try/catch block? If so, what is the correct syntax?
Thanks.