如何在Jenkins中允许catchError?

huangapple go评论76阅读模式
英文:

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]) {}

huangapple
  • 本文由 发表于 2020年7月29日 07:59:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63144431.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定