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

Passing variables to a Jenkinsfile shell script within "sh"

    Details

    • Similar Issues:

      Description

      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.

       

        Attachments

          Activity

          luhkevin Kevin Lu created issue -
          luhkevin Kevin Lu made changes -
          Field Original Value New Value
          Description 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.



           
          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.

           
          luhkevin Kevin Lu made changes -
          Description 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.

           
          I have a Jenkinsfile that looks roughly like this:

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

          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.

           
          abayer Andrew Bayer made changes -
          Component/s pipeline-model-definition-plugin [ 21706 ]
          Component/s pipeline [ 21692 ]
          abayer Andrew Bayer made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Not A Defect [ 7 ]
          abayer Andrew Bayer made changes -
          Resolution Not A Defect [ 7 ]
          Status Resolved [ 5 ] Reopened [ 4 ]
          abayer Andrew Bayer made changes -
          Component/s workflow-durable-task-step-plugin [ 21715 ]
          Component/s pipeline-model-definition-plugin [ 21706 ]

            People

            • Assignee:
              Unassigned
              Reporter:
              luhkevin Kevin Lu
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: