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

Empty env in pod template triggers NPE in org.csanchez.jenkins.plugins.kubernetes.pipeline.SecretsMasker

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins 2.235.1

      plugins
      -----------
      kubernetes 1.26.3
      kubernetes-client-api 4.9.2-2
      kubernetes-credentials 0.7.0
      kubernetes-pipeline-steps 1.6

      Steps to reproduce:

      Run the following pipeline script

      podTemplate(yaml: """
      apiVersion: v1
      kind: Pod
      metadata:
        labels:
          some-label: some-label-value
      spec:
        volumes:
        - name: containers-volume
        containers:
        - name: buildah
          image: quay.io/buildah/upstream
          imagePullPolicy: Always
          securityContext:
            privileged: true
          args:
          command:
          env:
          resources:
          volumeMounts:
          - mountPath: /var/lib/containers
            name: containers-volume
          command:
          - cat
          tty: true
      """
      ) {
          node(POD_LABEL) {
            container('buildah') {
              sh "buildah -v"
            }
          }
      }
      

      Actual results:

      The empty env specified for the container leads to the following error

      12:56:19  Agent marc.arens-lets-a-test-19-r5sb9-jbf1n-k3b0x is provisioned from template marc.arens_lets_a_test_19-r5sb9-jbf1n
      12:56:19  ---
      12:56:19  apiVersion: "v1"
      12:56:19  kind: "Pod"
      12:56:19  metadata:
      12:56:19    annotations:
      12:56:19      buildUrl: "https://jenkins.somecorp.com/job/marc.arens/job/lets_a_test/19/"
      12:56:19      runUrl: "job/marc.arens/job/lets_a_test/19/"
      12:56:19    labels:
      12:56:19      some-label: "some-label-value"
      12:56:19      jenkins: "slave"
      12:56:19      jenkins/label: "marc.arens_lets_a_test_19-r5sb9"
      12:56:19    name: "marc.arens-lets-a-test-19-r5sb9-jbf1n-k3b0x"
      12:56:19  spec:
      12:56:19    containers:
      12:56:19    - command:
      12:56:19      - "cat"
      12:56:19      image: "quay.io/buildah/upstream"
      12:56:19      imagePullPolicy: "Always"
      12:56:19      name: "buildah"
      12:56:19      securityContext:
      12:56:19        privileged: true
      12:56:19      tty: true
      12:56:19      volumeMounts:
      12:56:19      - mountPath: "/var/lib/containers"
      12:56:19        name: "containers-volume"
      12:56:19      - mountPath: "/home/jenkins/agent"
      12:56:19        name: "workspace-volume"
      12:56:19        readOnly: false
      12:56:19    - env:
      12:56:19      - name: "JENKINS_SECRET"
      12:56:19        value: "********"
      12:56:19      - name: "JENKINS_AGENT_NAME"
      12:56:19        value: "marc.arens-lets-a-test-19-r5sb9-jbf1n-k3b0x"
      12:56:19      - name: "JENKINS_NAME"
      12:56:19        value: "marc.arens-lets-a-test-19-r5sb9-jbf1n-k3b0x"
      12:56:19      - name: "JENKINS_AGENT_WORKDIR"
      12:56:19        value: "/home/jenkins/agent"
      12:56:19      - name: "JENKINS_URL"
      12:56:19        value: "https://jenkins.somecorp.com/"
      12:56:19      image: "jenkins/inbound-agent:4.3-4"
      12:56:19      name: "jnlp"
      12:56:19      resources:
      12:56:19        requests:
      12:56:19          cpu: "100m"
      12:56:19          memory: "256Mi"
      12:56:19      volumeMounts:
      12:56:19      - mountPath: "/home/jenkins/agent"
      12:56:19        name: "workspace-volume"
      12:56:19        readOnly: false
      12:56:19    nodeSelector:
      12:56:19      kubernetes.io/os: "linux"
      12:56:19    restartPolicy: "Never"
      12:56:19    volumes:
      12:56:19    - emptyDir:
      12:56:19        medium: ""
      12:56:19      name: "workspace-volume"
      12:56:19    - name: "containers-volume"
      12:56:19  
      12:56:19  Running on marc.arens-lets-a-test-19-r5sb9-jbf1n-k3b0x in /home/jenkins/agent/workspace/marc.arens/lets_a_test
      12:56:19  [Pipeline] {
      12:56:19  [Pipeline] container
      12:56:19  [Pipeline] // container
      12:56:19  [Pipeline] }
      12:56:19  [Pipeline] // node
      12:56:19  [Pipeline] }
      12:56:19  [Pipeline] // podTemplate
      12:56:19  [Pipeline] End of Pipeline
      12:56:19  java.lang.NullPointerException
      12:56:19  	at org.csanchez.jenkins.plugins.kubernetes.pipeline.SecretsMasker$Factory.secretsOf(SecretsMasker.java:150)
      12:56:19  	at org.csanchez.jenkins.plugins.kubernetes.pipeline.SecretsMasker$Factory.get(SecretsMasker.java:122)
      12:56:19  	at org.csanchez.jenkins.plugins.kubernetes.pipeline.SecretsMasker$Factory.get(SecretsMasker.java:94)
      12:56:19  	at org.jenkinsci.plugins.workflow.steps.DynamicContext$Typed.get(DynamicContext.java:94)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.ContextVariableSet.get(ContextVariableSet.java:138)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsThread.getContextVariable(CpsThread.java:135)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsStepContext.doGet(CpsStepContext.java:297)
      12:56:19  	at org.jenkinsci.plugins.workflow.support.DefaultStepContext.get(DefaultStepContext.java:67)
      12:56:19  	at org.jenkinsci.plugins.workflow.support.DefaultStepContext.getListener(DefaultStepContext.java:116)
      12:56:19  	at org.jenkinsci.plugins.workflow.support.DefaultStepContext.get(DefaultStepContext.java:79)
      12:56:19  	at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:264)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:263)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
      12:56:19  	at jdk.internal.reflect.GeneratedMethodAccessor748.invoke(Unknown Source)
      12:56:19  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      12:56:19  	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      12:56:19  	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      12:56:19  	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      12:56:19  	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      12:56:19  	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      12:56:19  	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      12:56:19  	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      12:56:19  	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      12:56:19  	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:163)
      12:56:19  	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
      12:56:19  	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
      12:56:19  	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:161)
      12:56:19  	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:165)
      12:56:19  	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
      12:56:19  	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:135)
      12:56:19  	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
      12:56:19  	at WorkflowScript.run(WorkflowScript:29)
      12:56:19  	at ___cps.transform___(Native Method)
      12:56:19  	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:86)
      12:56:19  	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
      12:56:19  	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
      12:56:19  	at jdk.internal.reflect.GeneratedMethodAccessor696.invoke(Unknown Source)
      12:56:19  	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      12:56:19  	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      12:56:19  	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      12:56:19  	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
      12:56:19  	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
      12:56:19  	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
      12:56:19  	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
      12:56:19  	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
      12:56:19  	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
      12:56:19  	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:185)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:400)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$400(CpsThreadGroup.java:96)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:312)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:276)
      12:56:19  	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
      12:56:19  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      12:56:19  	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
      12:56:19  	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      12:56:19  	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
      12:56:19  	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      12:56:19  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      12:56:19  	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      12:56:19  	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      12:56:19  	at java.base/java.lang.Thread.run(Thread.java:834)
      12:56:19  Finished: FAILURE
      

      Expected results:

      Kubernetes pipeline can handle empty env

      12:55:08  Running on marc.arens-lets-a-test-18-nmvx6-t64st-r91k3 in /home/jenkins/agent/workspace/marc.arens/lets_a_test
      12:55:08  [Pipeline] {
      12:55:08  [Pipeline] container
      12:55:08  [Pipeline] {
      12:55:08  [Pipeline] sh
      12:55:11  + buildah -v
      12:55:11  buildah version 1.16.0-dev (image-spec 1.0.1-dev, runtime-spec 1.0.2-dev)
      12:55:11  [Pipeline] }
      12:55:11  [Pipeline] // container
      12:55:11  [Pipeline] }
      12:55:11  [Pipeline] // node
      12:55:11  [Pipeline] }
      12:55:11  [Pipeline] // podTemplate
      12:55:11  [Pipeline] End of Pipeline
      12:55:11  Finished: SUCCESS
      

            iocanel Ioannis Canellos
            marc_arens Marc Arens
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: