title: jenkins pipeline passing variables
body: <p>I have a pipeline and I'm building my image through a docker container and it output the image tag, I want to pass that image tag to next stage, when I echo it in the next stage it prints out. but when I use it in a shell it goes empty. here is my pipeline </p>
  
  <pre><code>pipeline {
    agent any
    stages {
      stage('Cloning Git') {
        steps {
        git( url: 'https://xxx@bitbucket.org/xxx/xxx.git',
              credentialsId: 'xxx',
              branch: 'master')
  
        }
      }
      stage('Building Image') {
        steps{
           script {
           env.IMAGE_TAG = sh script: "docker run -e REPO_APP_BRANCH=master -e REPO_APP_NAME=exampleservice -e DOCKER_HUB_REPO_NAME=exampleservice --volume /var/run/docker.sock:/var/run/docker.sock registry.xxxx/build", returnStdout: true
  
          }
        }
      }
  
      stage('Integration'){
        steps{
          script{
                  echo "passed: ${env.IMAGE_TAG}"
            sh """
              helm upgrade exampleservice charts/exampleservice --set image.tag=${env.IMAGE_TAG}
              """
              sh "sleep 5"
  
  
          }
        }
      }
  
    }
  }
  </code></pre>
  
  <p>pipeline output</p>
  
  <pre><code>[Pipeline] }
  [Pipeline] // script
  [Pipeline] }
  [Pipeline] // stage
  [Pipeline] stage
  [Pipeline] { (Integration)
  [Pipeline] script
  [Pipeline] {
  [Pipeline] echo
  passed: 
   b79c3bf-b6eec4f
  
  
  [Pipeline] sh
  [test101] Running shell script
  + helm upgrade exampleservice charts/exampleservice --set image.tag=
  </code></pre>
  
  <p>getting empty image tag</p>