Groovy沙箱在workflow-cps-global-lib-plugin

时间:2017-01-27 10:56:11

标签: jenkins jenkins-pipeline

我们正在使用https://github.com/jenkinsci/workflow-cps-global-lib-plugin,并使用它(git repo)为管道作业创建通用帮助程序。在尝试使用工作流lib repo中的类时,我遇到了groovy沙箱的问题。

我得到了这个例外:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified new <path_to_my_class>

通过阅读插件的文档,我得到的印象是这个常见的repo是可信的,并且那里定义的类不会被沙盒化。

此外,似乎如果没有&#34;类&#34;定义类。源文件中的关键字,即只是实现方法传递沙箱安全检查,否则。但是,如何在不定义类和构造函数的情况下使用参数化构造函数?

我想让以下用例工作而不被沙箱阻止。

in&#34; / org / mylib&#34;目录我使用以下实现定义了类MyClass.groovy。

package org.mylib

class MyClass implements Serializable {
    MyClass(String someString) {
        this.data = someString
    }

    String data

    String data() {
        return this.data
    }
}

为什么这会在沙盒中运行以及我如何解决它?

2 个答案:

答案 0 :(得分:0)

如果您没有获得旁边的批准按钮,则无法阻止。它很可能无法找到它。

布局为的实际documentation mentioned on the plugin site状态为:

(root)
+- src                     # Groovy source files
|   +- org
|       +- foo
|           +- Bar.groovy  # for org.foo.Bar class
+- vars
|   +- foo.groovy          # for global 'foo' variable
|   +- foo.txt             # help for 'foo' variable
+- resources               # resource files (external libraries only)
|   +- org
|       +- foo
|           +- bar.json    # static helper data for org.foo.Bar

所以我目前的猜测是你应该把它移到src目录。

答案 1 :(得分:0)

如果在类中提供了一个静态方法来创建实例(即工厂模式),它应该绕过安全插件的那个方面。

相关问题