[JIRA] (JENKINS-53512) unable to pass params values to shared library vars .groovy

已查看 394 次
跳至第一个未读帖子

DCHSUEH@GMAIL.COM (JIRA)

未读,
2018年9月11日 16:32:012018/9/11
收件人 jenkinsc...@googlegroups.com
Daniel Hsueh created an issue
 
Jenkins / Bug JENKINS-53512
unable to pass params values to shared library vars .groovy
Issue Type: Bug Bug
Assignee: vjuranek
Components: groovy-plugin
Created: 2018-09-11 20:31
Environment: jenkins 2.140
pipeline (workflow-aggregator) 2.5
workflow-api 2.29
workflow-cps 2.54
workflow-cps-global-lib 2.10
Priority: Minor Minor
Reporter: Daniel Hsueh

(probably/likely related to JENKINS-51166)

 

in a scripted pipeline using a shared library "vars" .groovy file, passing "params.*" values results in an exception 

 

java.lang.NullPointerException: Cannot get property (property) on null object

but if I define an intermediary variable and pass that, it works

I'm not sure how to explain it in groovy parlance, but an example should demonstrate:

shared-test/vars/paramEcho.groovy (provided via filesystem_scm 2.1):

 

#!/usr/bin/env groovy

def call(body) {
    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    node {
        echo "config=${config}"
    }
}

 

failing Jenkinsfile

 

#!groovy

@Library('shared-test') _

properties( [
    parameters([ booleanParam(name:'truefalse', defaultValue:true, description:'boolean')
    ,string(name:'stringthing', defaultValue:'mary had a little lamb', description:'string')
    ])
] )

paramEcho {
    booleanvalue = params.truefalse
    stringvalue = params.stringthing
}

 

result

[Pipeline] properties
[Pipeline] End of Pipeline
java.lang.NullPointerException: Cannot get property 'truefalse' on null object
 at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
 at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174) at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456) at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290) at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29) at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20) at WorkflowScript.run(WorkflowScript:14) at paramEcho.call(/var/lib/jenkins/jobs/test-jobs/jobs/test-paramEcho/builds/1/libs/shared-test/vars/paramEcho.groovy:7) at WorkflowScript.run(WorkflowScript:13) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74) at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30) at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66) at sun.reflect.GeneratedMethodAccessor341.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:122) at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64) 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

whereas this Jenkinsfile that passes values through intermediary

 

// code placeholder

result

 

 

// code placeholder

 

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

DCHSUEH@GMAIL.COM (JIRA)

未读,
2018年9月11日 16:41:032018/9/11
收件人 jenkinsc...@googlegroups.com
Daniel Hsueh updated an issue
Change By: Daniel Hsueh
(probably/likely related to JENKINS-51166)

 

in a scripted pipeline using a shared library "vars" .groovy file, passing "params.*" values results in an exception 


 
{code:java}

java.lang.NullPointerException: Cannot get property (property) on null object
{code}

but if I define an intermediary variable and pass that, it works

I'm not sure how to explain it in groovy parlance, but an example should demonstrate:

shared-test/vars/paramEcho.groovy (provided via filesystem_scm 2.1):


 
{code:java}

#!/usr/bin/env groovy

def call(body) {
    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body()

    node {
        echo "config=${config}"
    }
}
{code}
 

failing Jenkinsfile

 
{code:java}

#!groovy

@Library('shared-test') _

properties( [
    parameters([
booleanParam(name:'truefalse', defaultValue:true, description:'boolean')
    ,string(name:'stringthing', defaultValue:'mary had a little lamb', description:'string')
    ])
] )

paramEcho {
    booleanvalue = params.truefalse
    stringvalue = params.stringthing
}
{code}
 

result
{code:java}
{code}

whereas this Jenkinsfile that passes values through intermediary


 
{code:java}
// code placeholder #!groovy
{code}
result @Library('shared-test') _
properties( [
    parameters([
        booleanParam(name:'truefalse', defaultValue:true, description:'boolean')
        ,string(name:'stringthing', defaultValue:'mary had a little lamb', description:'string')
    ])
] )

def _booleanvalue = params.truefalse
def _stringvalue = params.stringthing

paramEcho {
    booleanvalue = _booleanvalue
    stringvalue = _stringvalue
}
{code}
succeeds
 
{code:java}
[Pipeline] properties
[Pipeline] node
Running on Jenkins in
/ var / code placeholder lib/jenkins/workspace/test-jobs/test-paramEcho
[Pipeline] {
[Pipeline] echo
config=[booleanvalue:true, stringvalue:mary had a little lamb]
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
{
code}
 

 
(switching resolveStrategy to OWNER_FIRST or OWNER_ONLY results in
{code:java}
config=[:]
{code}
)

dhruv.barochia34788@gmail.com (JIRA)

未读,
2019年5月15日 05:03:032019/5/15
收件人 jenkinsc...@googlegroups.com
回复全部
回复作者
转发
0 个新帖子