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

NPE in logInterpolationWarnings after latest changes to DSL.java

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: workflow-cps-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.263.3 multibranch pipeline
    • Similar Issues:
    • Released As:
      2.90

      Description

      We got such NPE witch breaks pipeline which wasn't happening few months ago with older Jenkins versions:

      java.lang.NullPointerException
      at org.jenkinsci.plugins.workflow.cps.DSL.lambda$logInterpolationWarnings$1(DSL.java:379)
      at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:174)
      at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1556)
      at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
      at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipelinhr e.java:472)
      at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
      at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
      at org.jenkinsci.plugins.workflow.cps.DSL.logInterpolationWarnings(DSL.java:380)

      ...

       

      the first line which fails is:
      host: 'clamav-${profile == 'pre' ? 'dev.my-namespace.svc.cluster.local' : profile}'

      (i found it by making reply many times removing other lines, but there's more lines that fail).

      profile is just a variable, not even a credentials.

       

      I think the problem is in this commit https://github.com/jenkinsci/workflow-cps-plugin/commit/67045a6dc0f8ea720ef36bb3fa4eb31ac1428e5d#diff-32b19cea17be6f1240f13dbf1705f752422c2ba8e3df105204d37a1961d7fe08R379 maybe envVars.get(e) is null?

       

      I've managed to workaround this with such first line in the step which fails and approve it in Manage Jenkins -> In-process Script Approval:
      org.jenkinsci.plugins.workflow.cps.DSL.UNSAFE_GROOVY_INTERPOLATION = "ignore"

        Attachments

          Activity

          Hide
          ma00 Andrii Melnyk added a comment -

          Denis K I have the same NPE in the logs, looks like  envVars.get(e,'')  fixes this

          Show
          ma00 Andrii Melnyk added a comment - Denis K I have the same NPE in the logs, looks like  envVars.get(e,'')   fixes this
          Hide
          carroll Carroll Chiou added a comment -

          Denis K Thanks for the catch. I have a PR here for the fix: https://github.com/jenkinsci/workflow-cps-plugin/pull/419

          The only question I have is if you could be more specific in how this error was able to be generated? I can't tell exactly why your line

          host: 'clamav-${profile == 'pre' ? 'dev.my-namespace.svc.cluster.local' : profile}'

          would even fail without better context of your pipeline. Normally, if you try and access an environment variable that does not exist, it would be caught well before this code. This is definitely a bug, I just want to be able to get a proper test case for this to prevent any regressions.

          Might Andrii Melnyk have an example as well?

          Show
          carroll Carroll Chiou added a comment - Denis K Thanks for the catch. I have a PR here for the fix: https://github.com/jenkinsci/workflow-cps-plugin/pull/419 The only question I have is if you could be more specific in how this error was able to be generated? I can't tell exactly why your line host: 'clamav-${profile == 'pre' ? 'dev.my-namespace.svc.cluster.local' : profile}' would even fail without better context of your pipeline. Normally, if you try and access an environment variable that does not exist, it would be caught well before this code. This is definitely a bug, I just want to be able to get a proper test case for this to prevent any regressions. Might Andrii Melnyk have an example as well?
          Hide
          garazdawi Lukas added a comment -

          The issue seems to happen to me when I basically do:

          def image = docker.image(...).
          image.inside {
            withCredentials([sshUserPrivateKey(...)]) {
              def value = sh(script: "echo something", returnStdout: true);
              sh("echo \"${value}\"");
              // do some stuff with value
            }
          }
          

          It crashes when executing sh("echo ....") from what I can tell.

          Show
          garazdawi Lukas added a comment - The issue seems to happen to me when I basically do: def image = docker.image(...). image.inside { withCredentials([sshUserPrivateKey(...)]) { def value = sh(script: "echo something" , returnStdout: true ); sh( "echo \" ${value}\""); // do some stuff with value } } It crashes when executing sh("echo ....") from what I can tell.
          Hide
          ma00 Andrii Melnyk added a comment - - edited

          Carroll Chiou I can reproduce it with the following minimal pipeline:

          pipeline {
              agent any
              environment {
                  CREDS_SERVICEX = credentials 'servicex-user'
              }
              stages {
                  stage 'init', {
                      steps {
                          sh 'env'
                      }
                  }
              }
          }
          
          Show
          ma00 Andrii Melnyk added a comment - - edited Carroll Chiou I can reproduce it with the following minimal pipeline: pipeline { agent any environment { CREDS_SERVICEX = credentials 'servicex-user' } stages { stage 'init' , { steps { sh 'env' } } } }

            People

            Assignee:
            carroll Carroll Chiou
            Reporter:
            denis111 Denis K
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: