简体   繁体   English

管道共享库jenkins不支持Groovy @Delegate类注释

[英]Groovy @Delegate class annotations are not supported in the pipeline shared library jenkins

jenkins ver. 詹金斯版 2.89.4 2.89.4
workflow-cps ver 2.42 工作流CPS版本2.42

When i try to run a pipeline that loads the library, i get the following exception: 当我尝试运行加载库的管道时,出现以下异常:

Unsupported expression for CPS transformation @ line -1, column -1

The Groovy class to which the link is referenced: 引用链接的Groovy类:

final class Bindings implements Serializable{
    @Delegate
    private final Map map

    Bindings(Map map) {
        this.map = map
    }

    @Override
    boolean containsKey(Object key) {
        return true
    }

    @Override
    Object get(Object key) {
        return map.getOrDefault(key, null)
    }
}

You can reproduce an exception in the pipeline or in the library like this: 您可以像这样在管道或库中重现异常:

def map = ["key":"value"]
Bindings bindings = new Bindings (map) 

Not sure offhand what the issue here is (other annotations do work). 不能立即确定这里的问题是什么(其他注释确实起作用)。 Maybe only applies to source-generating annotations. 也许仅适用于源生成的注释。 Anyway for any non-trivial library it will most likely make use of Groovy language features Sorry but exotic features are not generally available in Pipeline script. 无论如何,对于任何非平凡的库,它很可能都将使用Groovy语言功能。对不起,但管道脚本中通常不提供外来功能。 Lack of support for Groovy class annotations is not explicitly documented (as far as I can see) either in this plugin or in the workflow-cps-plugin https://github.com/jenkinsci/workflow-cps-plugin . 在该插件中或在工作流cps-plugin https://github.com/jenkinsci/workflow-cps-plugin中,都没有明确记录(据我所知)对Groovy类注释的缺乏支持。

It's a known Jenkins issue: JENKINS-45901 这是詹金斯的一个已知问题: JENKINS-45901

This has been open since August 2017. Looks like it isn't going to be fixed anytime soon: 该服务自2017年8月开始开放。看来它不会很快得到修复:

Not sure if there is any particular place where Groovy language support (or lack thereof) is exhaustively documented, but at any rate I would not expect this issue or anything like it to be addressed. 不知道是否有任何特定的地方详尽记录了Groovy语言支持(或缺乏),但是无论如何我都不希望这个问题或类似的东西得到解决。 The focus going forward is allowing external process execution, not wasting any more time on the CPS engine except in cases of security vulnerabilities or serious regressions. 今后的工作重点是允许外部流程执行,不要在CPS引擎上浪费更多时间,除非存在安全漏洞或严重倒退的情况。

I tried the combination of @Delegate with @NonCPS but the latter doesn't seem to have any effect on fields. 我尝试了@Delegate@NonCPS的组合,但是后者似乎对字段没有任何影响。

You'll have to implement the delegate methods yourself or try another solution. 您必须自己实现委托方法或尝试其他解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM