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

NPE in branch condition

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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)
      

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Ah-ha - should be an easy fix

            Show
            abayer Andrew Bayer added a comment - Ah-ha - should be an easy fix
            Show
            abayer Andrew Bayer added a comment - PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/119
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/BranchConditional.java
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
            pipeline-model-definition/src/test/resources/whenBranchNull.groovy
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/c32520a90a360e6b3d9f6700d56bbca45f74d0b3
            Log:
            [FIXED JENKINS-42226] Treat null/empty branch comparison as false

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/impl/BranchConditional.java pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java pipeline-model-definition/src/test/resources/whenBranchNull.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/c32520a90a360e6b3d9f6700d56bbca45f74d0b3 Log: [FIXED JENKINS-42226] Treat null/empty branch comparison as false
            Hide
            imod Dominik Bartholdi added a comment -

            Andrew Bayer that was fast - thanks!

            Show
            imod Dominik Bartholdi added a comment - Andrew Bayer that was fast - thanks!

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                imod Dominik Bartholdi
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: