So I fixed one of my organisation's needs by adding a catchError
statement in one of their groovy files but in turn this creates a build error with a generic Jenkins test library BasePipelineTest
:
[main] ERROR org.apache.maven.plugin.surefire.SurefirePlugin - PipelineTest.testCall_AllFieldsAvailable:71 ? MissingMethod No signature
[main] ERROR org.apache.maven.plugin.surefire.SurefirePlugin - PipelineTest.testCall_FieldsNotAvailable:130 ? MissingMethod No signature
As part of the Jenkins standard BasePipelineTest
class the solution for this is typically:
helper.registerAllowedMethod("cleanWs", []) {}
For a method like cleanWs()
, or something similar depending on the method and its inputs. However this is for methods with input values, but catchError
doesn't have input values, rather it's done like:
catchError {
...
}
So helper.registerAllowedMethod("catchError", []) {}
does not work. Does anyone know how to make it work for something like catchError
?
I have also attempted:
helper.registerAllowedMethod("catchError", [com.lesfurets.jenkins.unit.catchError]) {}
This creates a MissingProperty
error
Turns out the curly brackets themselves register as a class in groovy. I fixed it with:
helper.registerAllowedMethod("catchError", [Closure.class]) {}