英文:
How to allow catchError in Jenkins?
问题
以下是您要翻译的内容:
我通过在组织的一个Groovy文件中添加catchError语句来解决了其中一个需求,但这反而导致了一个与Jenkins通用测试库BasePipelineTest相关的构建错误:
[main] ERROR org.apache.maven.plugin.surefire.SurefirePlugin - PipelineTest.testCall_AllFieldsAvailable:71 ? MissingMethod 无签名
[main] ERROR org.apache.maven.plugin.surefire.SurefirePlugin - PipelineTest.testCall_FieldsNotAvailable:130 ? MissingMethod 无签名
作为Jenkins标准BasePipelineTest类的一部分,解决此问题通常是:
helper.registerAllowedMethod("cleanWs", []) {}
对于类似于cleanWs()的方法,或者根据方法及其输入的不同情况可能有类似的方法。然而,对于没有输入值的catchError,它的用法如下:
catchError {
...
}
因此,helper.registerAllowedMethod("catchError", []) {}不起作用。是否有人知道如何使其适用于类似catchError的情况?
我还尝试过:
helper.registerAllowedMethod("catchError", [com.lesfurets.jenkins.unit.catchError]) {}
这会导致MissingProperty错误。
英文:
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
答案1
得分: 0
"Turns out the curly brackets themselves register as a class in groovy. I fixed it with:
helper.registerAllowedMethod("catchError", [Closure.class]) {}"
英文:
Turns out the curly brackets themselves register as a class in groovy. I fixed it with:
helper.registerAllowedMethod("catchError", [Closure.class]) {}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论