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

Pod or container environment variables are not recognized in declarative pipeline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Major Major
    • kubernetes-plugin
    • Jenkins 2.89
      kubernetes 1.8.0
      blueocean 1.3.1

      I have declarative Jenkinsfile and when I try to build the project it fails because the Jenkinsfile is not valid. This is the Jenkinsfile and the full error log
       

      // code placeholder
      pipeline {
        agent {
          kubernetes {
            label 'dotnet'
            containerTemplate {
              name 'dotnet'
              image 'microsoft/aspnetcore-build:2-jessie'
              ttyEnabled true
              command 'cat'
              envVars {
                envVar { 
                  key 'VERSION'
                  value '0.0.1'
                }
              }
            }
          }
        }
        stages {
          stage('Build and pack') {
            steps {
              container('dotnet') {
                dir ("src") {
                  sh 'echo ${VERSION}'
                  sh 'dotnet restore'
                  sh 'dotnet pack /p:PackageVersion=${VERSION} -c Release --include-source'
                }
              }
            }
          }
        }
      }
      

       

      Branch indexing
      
      [Pipeline] End of Pipeline
      
      GitHub has been notified of this commit’s build result
      
      java.lang.UnsupportedOperationException: must specify $class with an implementation of interface java.util.List
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.resolveClass(DescribableModel.java:452)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:379)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:338)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:261)
      Caused: java.lang.IllegalArgumentException: Could not instantiate {image=microsoft/aspnetcore-build:2-jessie, ttyEnabled=true, name=dotnet, envVars={envVar={key=VERSION, value=0.0.1}}, command=cat} for ContainerTemplate(name?: String, image?: String, alwaysPullImage?: boolean, args?: String, command?: String, envVars?: TemplateEnvVar{ContainerEnvVar(key: String, value: String) | KeyValueEnvVar(key: String, value: String) | PodEnvVar(key: String, value: String) | SecretEnvVar(key: String, secretName: String, secretKey: String)}[], livenessProbe?: ContainerLivenessProbe(execArgs: String, timeoutSeconds: int, initialDelaySeconds: int, failureThreshold: int, periodSeconds: int, successThreshold: int), ports?: PortMapping(name?: String, containerPort?: int, hostPort?: int)[], privileged?: boolean, resourceLimitCpu?: String, resourceLimitMemory?: String, resourceRequestCpu?: String, resourceRequestMemory?: String, ttyEnabled?: boolean, workingDir?: String)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:380)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:318)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:259)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptDescriptor.newInstance(WithScriptDescriptor.java:74)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor.instanceForDescriptor(DeclarativeAgentDescriptor.java:147)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor$instanceForDescriptor$2.call(Unknown Source)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.model.Agent.getDeclarativeAgent(Agent.groovy:77)
      	at sun.reflect.GeneratedMethodAccessor673.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      	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:19)
      Caused: java.lang.IllegalArgumentException: Could not instantiate {label=dotnet, containerTemplate={name=dotnet, image=microsoft/aspnetcore-build:2-jessie, ttyEnabled=true, command=cat, envVars={envVar={key=VERSION, value=0.0.1}}}} for KubernetesDeclarativeAgent(label: String, containerTemplate: ContainerTemplate(name?: String, image?: String, alwaysPullImage?: boolean, args?: String, command?: String, envVars?: TemplateEnvVar{ContainerEnvVar(key: String, value: String) | KeyValueEnvVar(key: String, value: String) | PodEnvVar(key: String, value: String) | SecretEnvVar(key: String, secretName: String, secretKey: String)}[], livenessProbe?: ContainerLivenessProbe(execArgs: String, timeoutSeconds: int, initialDelaySeconds: int, failureThreshold: int, periodSeconds: int, successThreshold: int), ports?: PortMapping(name?: String, containerPort?: int, hostPort?: int)[], privileged?: boolean, resourceLimitCpu?: String, resourceLimitMemory?: String, resourceRequestCpu?: String, resourceRequestMemory?: String, ttyEnabled?: boolean, workingDir?: String), activeDeadlineSeconds?: int, cloud?: String, inheritFrom?: String, instanceCap?: int, nodeSelector?: String, serviceAccount?: String, workingDir?: String)
      	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptDescriptor.newInstance(WithScriptDescriptor.java:74)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor.instanceForDescriptor(DeclarativeAgentDescriptor.java:147)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor$instanceForDescriptor$2.call(Unknown Source)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.model.Agent.getDeclarativeAgent(Agent.groovy:77)
      	at sun.reflect.GeneratedMethodAccessor673.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
      	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
      	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
      	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:19)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.inDeclarativeAgent(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:423)
      	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:68)
      	at WorkflowScript.run(WorkflowScript:1)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
      	at sun.reflect.GeneratedMethodAccessor196.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      	at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
      	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
      	at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
      	at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
      	at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
      	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:122)
      	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
      	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      Finished: FAILURE
      

            csanchez Carlos Sanchez
            thetechgeek Gordan Jandreoski
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: