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

multi-branch stage with when-branch fails with NullPointerException after jenkins restart

    XMLWordPrintable

Details

    • workflow-cps-plugin 2801.vf82a_b_b_e3e8a_5

    Description

      Repro steps:

      • create multi-branch pipeline with the pipeline below
      • start pipeline, wait for "input" (approval) to be pending
      • restart the Jenkins service
      • click Proceed to allow the pipeline to continue
      • the second stage fails with the error below

      Notes:

      • if you do not restart Jenkins while the input stage is pending then the pipeline will complete successfully
      • this approach worked on version 2.325
      • it started failing on 2.332.3
      • it continues to fail on 2.346.1
      • note the use of "agent none" in the approval step to avoid blocking an agent while waiting on approval, and the use of "agent any" on the subsequent step to pull the source code and perform further actions

      Pipeline:

      pipeline {
          agent none
          stages {
              stage('Approval') {
                  agent none
                  when {
                      anyOf {
                          branch 'main'
                      }
                  }
                  steps {
                      script {
                          timeout(time: 7, unit: 'DAYS') {
                              milestone()
                              input "Approve?"
                          }
                      }
                  }
              }
              stage('After Approval') {
                  agent any
                  when {
                      anyOf {
                          branch 'main'
                      }
                  }
                  steps {
                      script {
                          echo env.BRANCH_NAME
                      }
                  }
              }
          }
      } 

       

      Error:

       

      java.lang.NullPointerException
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:41)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.BranchConditionalScript.evaluate(BranchConditionalScript.groovy:39)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.AnyOfConditionalScript.evaluate(AnyOfConditionalScript.groovy:40)
      	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.any(CpsDefaultGroovyMethods:2343)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.AnyOfConditionalScript.evaluate(AnyOfConditionalScript.groovy:39)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter$WhenEvaluator.evaluateWhen(ModelInterpreter.groovy:856)
      	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.every(CpsDefaultGroovyMethods:2228)
      	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.every(CpsDefaultGroovyMethods:2249)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter$WhenEvaluator.evaluateWhen(ModelInterpreter.groovy:855)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter$WhenEvaluator.evaluateWhen(ModelInterpreter.groovy)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter$WhenEvaluator.passedOrNotEvaluated(ModelInterpreter.groovy:846)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.evaluateStage(ModelInterpreter.groovy:273)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(ModelInterpreter.groovy:595)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(CheckoutScript.groovy:61)
      	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.fixArg(FunctionCallBlock.java:83)
      	at jdk.internal.reflect.GeneratedMethodAccessor363.invoke(Unknown Source)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      	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:136)
      	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
      	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:187)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:95)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	at java.base/java.lang.Thread.run(Thread.java:829)

       

      For reference, BranchConditionalScript.groovy:39

      String branchName = (String)script.getProperty("env").getProperty("BRANCH_NAME") 

      Attachments

        Issue Links

          Activity

            markwaddle Mark Waddle added a comment - - edited

            as a non-ideal work-around, on the stages after the approval stage, i'm using script blocks to filter by branch, instead of using `when`

             

             

            steps {
                script {
                    // branch/tag check is implemented as a script to work-around a bug in the "when" block
                    // https://issues.jenkins.io/browse/JENKINS-68849
                    if (env.BRANCH_NAME != 'main') {
                        return
                    }
                    ...
                }
            }

             

             

            markwaddle Mark Waddle added a comment - - edited as a non-ideal work-around, on the stages after the approval stage, i'm using script blocks to filter by branch, instead of using `when`     steps { script { // branch/tag check is implemented as a script to work-around a bug in the "when" block // https://issues.jenkins.io/browse/JENKINS-68849 if (env.BRANCH_NAME != 'main' ) { return } ... } }    
            dnusbaum Devin Nusbaum added a comment - I think that https://github.com/jenkinsci/workflow-cps-plugin/pull/587 should fix this issue.

            I confirm this fixes the issue, as well as JENKINS-68937.

            capf Carsten Pfeiffer added a comment - I confirm this fixes the issue, as well as JENKINS-68937 .

            People

              dnusbaum Devin Nusbaum
              markwaddle Mark Waddle
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: