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

Environment variables are not exposed in pipeline script

XMLWordPrintable

    • 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
      

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

              Created:
              Updated:
              Resolved: