管道共享库jenkins不支持Groovy @Delegate类注释 [英] Groovy @Delegate class annotations are not supported in the pipeline shared library jenkins

查看:232
本文介绍了管道共享库jenkins不支持Groovy @Delegate类注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

詹金斯版2.89.4
工作流-cps版本2.42

当我尝试运行加载库的管道时,出现以下异常:

jenkins ver. 2.89.4
workflow-cps ver 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

链接所引用的Groovy类:

The Groovy class to which the link is referenced:

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) 

推荐答案

这是一个已知的Jenkins问题:

It's a known Jenkins issue: JENKINS-45901

此服务自2017年8月开始开放.看来它不会很快得到修复:

This has been open since August 2017. Looks like it isn't going to be fixed anytime soon:

不确定是否在任何特定地方都详尽记录了Groovy语言支持(或缺乏),但是无论如何我都不希望这个问题或类似的问题得到解决.今后的工作重点是允许外部流程执行,而不是在安全漏洞或严重倒退的情况下,不再在CPS引擎上浪费更多的时间.

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. 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.

我尝试了@Delegate@NonCPS的组合,但是后者似乎对字段没有任何影响.

I tried the combination of @Delegate with @NonCPS but the latter doesn't seem to have any effect on fields.

您必须自己实现委托方法或尝试其他解决方案.

You'll have to implement the delegate methods yourself or try another solution.

这篇关于管道共享库jenkins不支持Groovy @Delegate类注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆