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

Jenkins pipeline multi line sh script behave different in access global variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • pipeline
    • None
    • Jenkins ver. 2.107.3

      A global variable can be print in single line shell but not in multi line script. With the script:

      def my_var = "my_value"
      pipeline {
          agent any
          stages {
              stage('Build') {
                  steps {
                      sh "echo my_var=${my_var}"
                      sh '''
                          echo my_var=${my_var}
                      '''
                  }
              }
          }
      }
      

      I got the result:

      [Pipeline] sh
      + echo my_var=my_value
      my_var=my_value
      [Pipeline] sh
      + echo my_var=
      my_var=
      [Pipeline] }
      

            Unassigned Unassigned
            simon_le Simon Le
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: