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

NPE: Cannot invoke method getScript() on null object in stage/agent/label

XMLWordPrintable

      This declarative script:

      #!groovy
      
      def cdnInput = null
      
      pipeline{
        agent none
      
        stages {
      
          stage("Input"){
            agent any
            steps {
              script {
                cdnInput = input (message: 'Deploy to CDN?', ok: 'Authorize',
                parameters:
                  [choice(choices: ['qa-us-jenkins01', 'jenkins01_deploy_prod'].join("\n"),
                  description: 'To which CDN should be the artifacts deployed?', name: 'cdnEnv')])
              }
            }
          }
      
          stage('Echo in step'){
            agent any
            steps {
              echo cdnInput
            }
          }
      
          stage('NPE'){
            agent { label cdnInput }
            steps {
              echo "Never happens ${cdnInput}"
            }
          }
        }
      }
      

      Fails with NPE on the `agent { label cdnInput }` part even though the value is defined:

      [Pipeline] stage
      [Pipeline] { (Input)
      [Pipeline] node
      Running on storagesync_builder_02 in /home/jenkins-slave/workspace/test-pipe_jbochenski
      [Pipeline] {
      [Pipeline] script
      [Pipeline] {
      [Pipeline] input
      Input requested
      Approved by jbochenski
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Echo in step)
      [Pipeline] node
      Running on Win10_64b_off2016_64b_EGD in C:\jenkins\workspace\test-pipe_jbochenski
      [Pipeline] {
      [Pipeline] echo
      qa-us-jenkins01
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (NPE)
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      java.lang.NullPointerException: Cannot invoke method getScript() on null object
      	at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:372)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/lib/jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:95)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
      	at sun.reflect.GeneratedMethodAccessor733.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.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:76)
      	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.GeneratedMethodAccessor737.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:173)
      	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:162)
      	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:162)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
      	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:112)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	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:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      Finished: FAILURE

      Changing the above to `agent { node { label cdnInput }` results in the stage executing on a random node (different on each build)

      [Pipeline] stage
      [Pipeline] { (Input)
      [Pipeline] node
      Running on Win10_64b_off2016_64b_EGD in C:\jenkins\workspace\test-pipe_jbochenski
      [Pipeline] {
      [Pipeline] script
      [Pipeline] {
      [Pipeline] input
      Input requested
      Approved by jbochenski
      [Pipeline] }
      [Pipeline] // script
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (Echo in step)
      [Pipeline] node
      Running on IQ3-55d0ec9760c0 in /home/egnyte/workspace/test-pipe_jbochenski
      [Pipeline] {
      [Pipeline] echo
      qa-us-jenkins01
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (NPE)
      [Pipeline] node
      Running on Win2012R2Server in C:\JenkinsSlave\workspace\test-pipe_jbochenski
      [Pipeline] {
      [Pipeline] echo
      Never happens qa-us-jenkins01
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      Finished: SUCCESS

            abayer Andrew Bayer
            jbochenski Jakub Bochenski
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: