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

Passing variables to a Jenkinsfile shell script within "sh"

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.

       

            Unassigned Unassigned
            luhkevin Kevin Lu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: