jenkins pipeline passing variables











up vote
0
down vote

favorite












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



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"


}
}
}

}
}


pipeline output



[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=


getting empty image tag










share|improve this question




























    up vote
    0
    down vote

    favorite












    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



    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"


    }
    }
    }

    }
    }


    pipeline output



    [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=


    getting empty image tag










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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



      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"


      }
      }
      }

      }
      }


      pipeline output



      [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=


      getting empty image tag










      share|improve this question















      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



      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"


      }
      }
      }

      }
      }


      pipeline output



      [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=


      getting empty image tag







      jenkins jenkins-pipeline






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 9:23

























      asked Nov 9 at 9:01









      Jack

      275




      275
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You should override this by using the 'env'.



          Replace your code with this one:



          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"


          }
          }
          }

          }
          }





          share|improve this answer























          • im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
            – Jack
            Nov 9 at 9:24










          • I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
            – yorammi
            Nov 9 at 13:13










          • --set image.tag="${env.IMAGE_TAG}" this worked
            – Jack
            Nov 12 at 5:39











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222616%2fjenkins-pipeline-passing-variables%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You should override this by using the 'env'.



          Replace your code with this one:



          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"


          }
          }
          }

          }
          }





          share|improve this answer























          • im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
            – Jack
            Nov 9 at 9:24










          • I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
            – yorammi
            Nov 9 at 13:13










          • --set image.tag="${env.IMAGE_TAG}" this worked
            – Jack
            Nov 12 at 5:39















          up vote
          1
          down vote



          accepted










          You should override this by using the 'env'.



          Replace your code with this one:



          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"


          }
          }
          }

          }
          }





          share|improve this answer























          • im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
            – Jack
            Nov 9 at 9:24










          • I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
            – yorammi
            Nov 9 at 13:13










          • --set image.tag="${env.IMAGE_TAG}" this worked
            – Jack
            Nov 12 at 5:39













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You should override this by using the 'env'.



          Replace your code with this one:



          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"


          }
          }
          }

          }
          }





          share|improve this answer














          You should override this by using the 'env'.



          Replace your code with this one:



          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"


          }
          }
          }

          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 19:09

























          answered Nov 9 at 9:06









          yorammi

          2,9911524




          2,9911524












          • im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
            – Jack
            Nov 9 at 9:24










          • I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
            – yorammi
            Nov 9 at 13:13










          • --set image.tag="${env.IMAGE_TAG}" this worked
            – Jack
            Nov 12 at 5:39


















          • im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
            – Jack
            Nov 9 at 9:24










          • I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
            – yorammi
            Nov 9 at 13:13










          • --set image.tag="${env.IMAGE_TAG}" this worked
            – Jack
            Nov 12 at 5:39
















          im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
          – Jack
          Nov 9 at 9:24




          im still getting null value to my env.IMAGE_TAG in sh, but echo is working i have edit my question with pipeline output
          – Jack
          Nov 9 at 9:24












          I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
          – yorammi
          Nov 9 at 13:13




          I've edited my answer. You should not put the 'env.' prefix in the 'sh' part
          – yorammi
          Nov 9 at 13:13












          --set image.tag="${env.IMAGE_TAG}" this worked
          – Jack
          Nov 12 at 5:39




          --set image.tag="${env.IMAGE_TAG}" this worked
          – Jack
          Nov 12 at 5:39


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222616%2fjenkins-pipeline-passing-variables%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word