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

parameters are not available as environment variables in pod containers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • kubernetes-plugin
    • None
    • Jenkins 2.73.1 Kubernetes plugin 1.0

      Pipeline parameters are not available as environment variables in the pod containers that aren't the JNLP container.

      This Jenkinsfile produces output showing the issue:

      properties([
          parameters([
              string(name: 'PARAM_TEST', defaultValue: 'foo', description: ''),
          ]),
      ])
      
      podTemplate(
          cloud: 'kubernetes',
          containers: [
              containerTemplate(
                  alwaysPullImage: false,
                  envVars: [],
                  image: 'alpine',
                  name: 'alpine',
                  privileged: false,
                  ttyEnabled: true,
              ),
          ],
          serviceAccount: 'jenkins',
          idleMinutes: 0,
          instanceCap: 2,
          label: 'test-pipeline',
          name: 'test-pipeline',
      ) {
          node ('test-pipeline') {
              sh 'echo \$PARAM_TEST: $PARAM_TEST'
              container('alpine') {
                  sh 'echo \$PARAM_TEST: $PARAM_TEST'
              }
          }
      }
      
      

      Output:

      Started by user chance.zibolski
      [Pipeline] properties
      [Pipeline] podTemplate
      [Pipeline] {
      [Pipeline] node
      Running on test-pipeline-xchj7-gcv7h in /home/jenkins/workspace/test-pipeline
      [Pipeline] {
      [Pipeline] sh
      [test-pipeline] Running shell script
      + echo foo: foo
      foo: foo
      [Pipeline] container
      [Pipeline] {
      [Pipeline] sh
      [test-pipeline] Running shell script
      + echo :
      :
      [Pipeline] }
      [Pipeline] // container
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // podTemplate
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

            Unassigned Unassigned
            chancez Chance Zibolski
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: