Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-53512

unable to pass params values to shared library vars .groovy

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • groovy-plugin
    • None
    • jenkins 2.140
      pipeline (workflow-aggregator) 2.5
      workflow-api 2.29
      workflow-cps 2.54
      workflow-cps-global-lib 2.10

      (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 

      #!groovy
      
      @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
      }
      

      succeeds 

      [Pipeline] properties
      [Pipeline] node
      Running on Jenkins in /var/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 
      

       

       (switching resolveStrategy to OWNER_FIRST or OWNER_ONLY results in

      config=[:]
      

      )

            vjuranek vjuranek
            dchsueh Daniel Hsueh
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: