为什么这个简单的Groovy脚本在Jenkins管道中失败?

克里斯·F

我可以在Groovy和Jenkins的脚本控制台中运行它。

def generator = { String alphabet, int n ->
  new Random().with {
    (1..n).collect { alphabet[ nextInt( alphabet.length() ) ] }.join()
  }
}

node('node-0') {
    stage('test') {
        println generator( (('A'..'Z')+('0'..'9')).join(), 9 )
    }
}

但是当我在管道中运行它时,我得到了。为什么?

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.join() is applicable for argument types: () values: []
Possible solutions: join(java.lang.String), min(), min(java.util.Comparator), min(groovy.lang.Closure), wait(), find()
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:153)
    at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:162)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
    at WorkflowScript.run(WorkflowScript:11)
    at ___cps.transform___(Native Method)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:78)
    at sun.reflect.GeneratedMethodAccessor338.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
zett42

我让它像这样工作,但是我无法确切回答“为什么”。join()使用Groovy沙箱时,不带参数重载显然不可用。.with{}由于CPS转换,方法可能无法正常工作(无论是否具有“ Groovy沙箱”,方法均不起作用)。

def generator = { String alphabet, int n ->
  def rnd = new Random()   // because .with{} doesn't work
  (1..n).collect { alphabet[ rnd.nextInt( alphabet.length() ) ] }.join('')
}

node('node-0') {
    stage('test') {
        println generator( (('A'..'Z')+('0'..'9')).join(''), 9 )
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么这个简单的断言在python中失败?

为什么这个简单的minitest失败了?

为什么这个简单的网络抓取失败了?

在Jenkins中调试Groovy脚本化管道

Jenkins 脚本管道:Groovy if 语句

为什么我的 POST 在这个简单的 VueJS 表单中失败?

为什么这个简单的while循环在bash脚本中不起作用?

为什么这个简单的 javascript 数组会失败?

为什么这个简单布尔逻辑的 pytest 失败了?

为什么这个简单的“hello world”Urwid 代码会失败?

为什么这个简单的iCloud存储应用失败了?

为什么这个简单的MemoryStream.Write()实验失败了?

MySQL,为什么这个简单的“ CREATE TABLE”查询失败?

为什么这个简单的php脚本不起作用?

为什么这个简单的Powershell脚本在需要时不退出?

为什么这个简单的 kusto 脚本不起作用?

在jenkins声明式管道文件中重用groovy脚本

为什么在Jenkins管道中的第二个节点上踩sh失败?

为什么这种常规代码在jenkins管道脚本中的工作方式不同

为什么此Groovy脚本在Jenkins中无法获取作业参数?

Jenkins Groovy管道简单继承故障

Groovy中这个脚本字段是什么意思?

由于 Maven,简单的 Jenkins 管道构建失败

为什么这个简单的查询不使用postgres中的索引?

PyTorch:在这个简单的例子中,为什么损失不变?

为什么这个简单的模型在tensorflow中占用大量内存?

脚本化的Jenkins管道:失败后继续

为什么这个脚本在Python中这么慢?

为什么我的Groovy脚本在Jenkins脚本控制台中运行却不能作为Groovy Postbuild脚本运行?