为了账号安全,请及时绑定邮箱和手机立即绑定

Jenkins CI管道脚本不允许使用方法groovy.lang.GroovyObject

Jenkins CI管道脚本不允许使用方法groovy.lang.GroovyObject

我正在使用Jenkins 2来编译Java项目,我想从pom.xml中读取版本,我在遵循以下示例:https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md该示例建议:似乎在访问文件系统时存在一些安全问题,但我无法弄清楚它给了什么(或为什么)该问题:我只是在做一些与示例不同的事情:def version() {    String path = pwd();    def matcher = readFile("${path}/pom.xml") =~ '<version>(.+)</version>'    return matcher ? matcher[0][1] : null}运行'version'方法时出现的错误:org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (org.codehaus.groovy.runtime.GStringImpl call org.codehaus.groovy.runtime.GStringImpl)    at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectMethod(StaticWhitelist.java:165)    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:117)    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103)    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)    at WorkflowScript.run(WorkflowScript:71)    at ___cps.transform___(Native Method)    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)    at sun.reflect.GeneratedMethodAccessor408.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)我正在使用以下版本:Plugin Pipeline 2.1 Jenkins 2.2
查看完整描述

3 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

快速解决


我遇到了类似的问题,并通过以下措施解决了它


导航到jenkins>管理jenkins>进程内脚本批准

有一个待批准的命令,我必须批准。

//img1.sycdn.imooc.com//5daacfe30001c0a411260094.jpg

选择1:禁用沙箱


正如本文深入解释的那样,默认情况下,groovy脚本在沙箱模式下运行。这意味着可以在无需管理员许可的情况下运行常规方法的子集。也可以不在沙盒模式下运行脚本,这意味着整个脚本需要立即获得管理员的批准。这样可以防止用户同时批准每一行。


通过在脚本下方的项目配置中取消选中此复选框,可以运行没有沙箱的脚本: 

//img1.sycdn.imooc.com//5daacfe900015ee310380471.jpg

选择2:禁用脚本安全性


如本文所述,还可以完全禁用脚本安全性。首先安装许可脚本安全性插件,然后更改您的jenkins.xml文件,添加以下参数:


-Dpermissive-script-security.enabled = true


因此,您的jenkins.xml将如下所示:


<executable>..bin\java</executable>

<arguments>-Dpermissive-script-security.enabled=true -Xrs -Xmx4096m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=80 --webroot="%BASE%\war"</arguments>

如果执行此操作,请确保您知道自己在做什么!


查看完整回答
反对 回复 2019-10-19
?
元芳怎么了

TA贡献1798条经验 获得超7个赞

我将userInput中用户输入参数的数量从3减少到1时遇到了这种情况。这将userInput的变量输出类型从数组更改为原始类型。


例:


myvar1 = userInput['param1']

myvar2 = userInput['param2']

至:


myvar = userInput


查看完整回答
反对 回复 2019-10-19
  • 3 回答
  • 0 关注
  • 2626 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信