Passing variables to a Jenkinsfile shell script within "sh"

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      I have a Jenkinsfile that looks roughly like this:

       

      ...
      stage('Build') {
           steps {
               script {
                   FOO = sh (script: "echo bar", returnStdout: true)
               }
           }
      }
      stage('Plan') {
           steps {
               sh "FOO=${FOO} ./tests/run.sh"
           }
      }
      ...
      

       

      Why am I not seeing the variable $FOO within run.sh? This works in a regular shell and bash. Furthermore it's not like Jenkins isn't picking up the value of $FOO. It correctly prints the value of $FOO as "bar" in other places that I've used it.

       

            Assignee:
            Unassigned
            Reporter:
            Kevin Lu
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: