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

NPE in branch condition

XMLWordPrintable

      This pipeline fails with a NullPointerException:

      config = [:]
      
      pipeline {
          agent any
          stages {
              stage ('prepare') {
                  when {
                      branch config.branch
                  }
                  steps {
                      echo "hello branch"            
                  }
              }
          }
      }
      

      I know, the pipeline might look a bit strange with having a config/map defined - but in our real pipeline, we have some logic to select the correct config/map object before the pipeline starts. This allows us to reuse a lot more...

      exception:

      java.lang.NullPointerException
      	at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.BranchConditional.branchMatches(BranchConditional.java:64)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.BranchConditional$branchMatches.call(Unknown Source)
      	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)
      

            abayer Andrew Bayer
            imod Dominik Bartholdi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: