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

Environment variables are not exposed in pipeline script

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • p4-plugin
    • None

      Hi,

      Following p4-plugin exposed variables - I would expect the following code to work:

      node ('somenode')
      {
          stage ('checkout')
          {
              checkout([
                  $class: 'PerforceScm', 
                  credential: '111111111-1111-1111-1111-111111111111', //not actual value
                  populate: [
                      $class: 'ForceCleanImpl', 
                      have: false,
                      parallel: [
                          enable: false,
                          minbytes: '1024',
                          minfiles: '1', 
                          path: '/usr/local/bin/p4',
                          threads: '4'
                          ], 
                      pin: '', 
                      quiet: true
                      ], 
                  workspace: [
                      $class: 'ManualWorkspaceImpl', 
                      charset: 'none', 
                      name: "jenkins-${NODE_NAME}-${JOB_NAME}", 
                      pinHost: false, 
                      spec: [
                          allwrite: false, 
                          clobber: false, 
                          compress: false, 
                          line: 'LOCAL', 
                          locked: false, 
                          modtime: false, 
                          rmdir: false, 
                          streamName: '', 
                          view: "//Depot/... //jenkins-${NODE_NAME}-${JOB_NAME}/..."
                          ]
                      ]
                  ]
              )
          }
          
          println "P4_CHANGELIST=${env.P4_CHANGELIST}"
          println "P4_CLIENT=${env.P4_CLIENT}"
          println "P4_PORT=${env.P4_PORT}"
          println "P4_USER=${env.P4_USER}"
          println "P4_TICKET=${env.P4_TICKET}"
          println "HUDSON_CHANGELOG_FILE=${env.HUDSON_CHANGELOG_FILE}"
          sh 'echo $P4_CHANGELIST'
      }
      

      But all I get are nulls even though the build does have changes (i.e I purge the build history and reset build # to 1 - then run the job manually for the 1st time).

      ...
      P4 Task: syncing files at change: 1703
      ...
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] echo
      P4_CHANGELIST=null
      [Pipeline] echo
      P4_CLIENT=null
      [Pipeline] echo
      P4_PORT=null
      [Pipeline] echo
      P4_USER=null
      [Pipeline] echo
      P4_TICKET=null
      [Pipeline] echo
      HUDSON_CHANGELOG_FILE=null
      [Pipeline] sh
      [UI-CSR-Dev-tag test] Running shell script
      + echo
      
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS
      

          [JENKINS-40885] Environment variables are not exposed in pipeline script

          Mor L created issue -
          Mor L made changes -
          Description Original: Hi,

          Following this [p4-plugin exposed variables|https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md#exposed-variables] - I would expect the following code to work:


          {code:java}
          node ('somenode')
          {
              stage ('checkout')
              {
                  checkout([
                      $class: 'PerforceScm',
                      credential: '111111111-1111-1111-1111-111111111111', //not actual value
                      populate: [
                          $class: 'ForceCleanImpl',
                          have: false,
                          parallel: [
                              enable: false,
                              minbytes: '1024',
                              minfiles: '1',
                              path: '/usr/local/bin/p4',
                              threads: '4'
                              ],
                          pin: '',
                          quiet: true
                          ],
                      workspace: [
                          $class: 'ManualWorkspaceImpl',
                          charset: 'none',
                          name: "jenkins-${NODE_NAME}-${JOB_NAME}",
                          pinHost: false,
                          spec: [
                              allwrite: false,
                              clobber: false,
                              compress: false,
                              line: 'LOCAL',
                              locked: false,
                              modtime: false,
                              rmdir: false,
                              streamName: '',
                              view: "//Depot/... //jenkins-${NODE_NAME}-${JOB_NAME}/..."
                              ]
                          ]
                      ]
                  )
              }
              
              println "P4_CHANGELIST=${env.P4_CHANGELIST}"
              println "P4_CLIENT=${env.P4_CLIENT}"
              println "P4_PORT=${env.P4_PORT}"
              println "P4_USER=${env.P4_USER}"
              println "P4_TICKET=${env.P4_TICKET}"
              println "HUDSON_CHANGELOG_FILE=${env.HUDSON_CHANGELOG_FILE}"
              sh 'echo $P4_CHANGELIST'
          }
          {code}

          But all I get are nulls even though the build does have changes (i.e I purge the build history and reset build # to 1 - then run the job manually for the 1st time).

          {code:java}
          ...
          P4 Task: syncing files at change: 1703
          ...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] echo
          P4_CHANGELIST=null
          [Pipeline] echo
          P4_CLIENT=null
          [Pipeline] echo
          P4_PORT=null
          [Pipeline] echo
          P4_USER=null
          [Pipeline] echo
          P4_TICKET=null
          [Pipeline] echo
          HUDSON_CHANGELOG_FILE=null
          [Pipeline] echo
          null
          [Pipeline] sh
          [UI-CSR-Dev-tag test] Running shell script
          + echo

          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          {code}
          New: Hi,

          Following [p4-plugin exposed variables|https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md#exposed-variables] - I would expect the following code to work:


          {code:java}
          node ('somenode')
          {
              stage ('checkout')
              {
                  checkout([
                      $class: 'PerforceScm',
                      credential: '111111111-1111-1111-1111-111111111111', //not actual value
                      populate: [
                          $class: 'ForceCleanImpl',
                          have: false,
                          parallel: [
                              enable: false,
                              minbytes: '1024',
                              minfiles: '1',
                              path: '/usr/local/bin/p4',
                              threads: '4'
                              ],
                          pin: '',
                          quiet: true
                          ],
                      workspace: [
                          $class: 'ManualWorkspaceImpl',
                          charset: 'none',
                          name: "jenkins-${NODE_NAME}-${JOB_NAME}",
                          pinHost: false,
                          spec: [
                              allwrite: false,
                              clobber: false,
                              compress: false,
                              line: 'LOCAL',
                              locked: false,
                              modtime: false,
                              rmdir: false,
                              streamName: '',
                              view: "//Depot/... //jenkins-${NODE_NAME}-${JOB_NAME}/..."
                              ]
                          ]
                      ]
                  )
              }
              
              println "P4_CHANGELIST=${env.P4_CHANGELIST}"
              println "P4_CLIENT=${env.P4_CLIENT}"
              println "P4_PORT=${env.P4_PORT}"
              println "P4_USER=${env.P4_USER}"
              println "P4_TICKET=${env.P4_TICKET}"
              println "HUDSON_CHANGELOG_FILE=${env.HUDSON_CHANGELOG_FILE}"
              sh 'echo $P4_CHANGELIST'
          }
          {code}

          But all I get are nulls even though the build does have changes (i.e I purge the build history and reset build # to 1 - then run the job manually for the 1st time).

          {code:java}
          ...
          P4 Task: syncing files at change: 1703
          ...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] echo
          P4_CHANGELIST=null
          [Pipeline] echo
          P4_CLIENT=null
          [Pipeline] echo
          P4_PORT=null
          [Pipeline] echo
          P4_USER=null
          [Pipeline] echo
          P4_TICKET=null
          [Pipeline] echo
          HUDSON_CHANGELOG_FILE=null
          [Pipeline] echo
          null
          [Pipeline] sh
          [UI-CSR-Dev-tag test] Running shell script
          + echo

          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          {code}
          Mor L made changes -
          Description Original: Hi,

          Following [p4-plugin exposed variables|https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md#exposed-variables] - I would expect the following code to work:


          {code:java}
          node ('somenode')
          {
              stage ('checkout')
              {
                  checkout([
                      $class: 'PerforceScm',
                      credential: '111111111-1111-1111-1111-111111111111', //not actual value
                      populate: [
                          $class: 'ForceCleanImpl',
                          have: false,
                          parallel: [
                              enable: false,
                              minbytes: '1024',
                              minfiles: '1',
                              path: '/usr/local/bin/p4',
                              threads: '4'
                              ],
                          pin: '',
                          quiet: true
                          ],
                      workspace: [
                          $class: 'ManualWorkspaceImpl',
                          charset: 'none',
                          name: "jenkins-${NODE_NAME}-${JOB_NAME}",
                          pinHost: false,
                          spec: [
                              allwrite: false,
                              clobber: false,
                              compress: false,
                              line: 'LOCAL',
                              locked: false,
                              modtime: false,
                              rmdir: false,
                              streamName: '',
                              view: "//Depot/... //jenkins-${NODE_NAME}-${JOB_NAME}/..."
                              ]
                          ]
                      ]
                  )
              }
              
              println "P4_CHANGELIST=${env.P4_CHANGELIST}"
              println "P4_CLIENT=${env.P4_CLIENT}"
              println "P4_PORT=${env.P4_PORT}"
              println "P4_USER=${env.P4_USER}"
              println "P4_TICKET=${env.P4_TICKET}"
              println "HUDSON_CHANGELOG_FILE=${env.HUDSON_CHANGELOG_FILE}"
              sh 'echo $P4_CHANGELIST'
          }
          {code}

          But all I get are nulls even though the build does have changes (i.e I purge the build history and reset build # to 1 - then run the job manually for the 1st time).

          {code:java}
          ...
          P4 Task: syncing files at change: 1703
          ...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] echo
          P4_CHANGELIST=null
          [Pipeline] echo
          P4_CLIENT=null
          [Pipeline] echo
          P4_PORT=null
          [Pipeline] echo
          P4_USER=null
          [Pipeline] echo
          P4_TICKET=null
          [Pipeline] echo
          HUDSON_CHANGELOG_FILE=null
          [Pipeline] echo
          null
          [Pipeline] sh
          [UI-CSR-Dev-tag test] Running shell script
          + echo

          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          {code}
          New: Hi,

          Following [p4-plugin exposed variables|https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md#exposed-variables] - I would expect the following code to work:


          {code:java}
          node ('somenode')
          {
              stage ('checkout')
              {
                  checkout([
                      $class: 'PerforceScm',
                      credential: '111111111-1111-1111-1111-111111111111', //not actual value
                      populate: [
                          $class: 'ForceCleanImpl',
                          have: false,
                          parallel: [
                              enable: false,
                              minbytes: '1024',
                              minfiles: '1',
                              path: '/usr/local/bin/p4',
                              threads: '4'
                              ],
                          pin: '',
                          quiet: true
                          ],
                      workspace: [
                          $class: 'ManualWorkspaceImpl',
                          charset: 'none',
                          name: "jenkins-${NODE_NAME}-${JOB_NAME}",
                          pinHost: false,
                          spec: [
                              allwrite: false,
                              clobber: false,
                              compress: false,
                              line: 'LOCAL',
                              locked: false,
                              modtime: false,
                              rmdir: false,
                              streamName: '',
                              view: "//Depot/... //jenkins-${NODE_NAME}-${JOB_NAME}/..."
                              ]
                          ]
                      ]
                  )
              }
              
              println "P4_CHANGELIST=${env.P4_CHANGELIST}"
              println "P4_CLIENT=${env.P4_CLIENT}"
              println "P4_PORT=${env.P4_PORT}"
              println "P4_USER=${env.P4_USER}"
              println "P4_TICKET=${env.P4_TICKET}"
              println "HUDSON_CHANGELOG_FILE=${env.HUDSON_CHANGELOG_FILE}"
              sh 'echo $P4_CHANGELIST'
          }
          {code}

          But all I get are nulls even though the build does have changes (i.e I purge the build history and reset build # to 1 - then run the job manually for the 1st time).

          {code:java}
          ...
          P4 Task: syncing files at change: 1703
          ...
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] echo
          P4_CHANGELIST=null
          [Pipeline] echo
          P4_CLIENT=null
          [Pipeline] echo
          P4_PORT=null
          [Pipeline] echo
          P4_USER=null
          [Pipeline] echo
          P4_TICKET=null
          [Pipeline] echo
          HUDSON_CHANGELOG_FILE=null
          [Pipeline] sh
          [UI-CSR-Dev-tag test] Running shell script
          + echo

          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          {code}
          Staffan Forsell made changes -
          Link New: This issue is related to JENKINS-37584 [ JENKINS-37584 ]
          Paul Allen made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Paul Allen made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Progress [ 3 ] New: Resolved [ 5 ]
          Paul Allen made changes -
          Status Original: Resolved [ 5 ] New: Closed [ 6 ]
          James Dumay made changes -
          Remote Link New: This issue links to "CloudBees Internal OSS-2133 (Web Link)" [ 18407 ]

            Unassigned Unassigned
            pyrocks Mor L
            Votes:
            5 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: