0

I'm creating a Jenkins pipeline for simple deployment into kubernetes cluster, I have my private Docker registry, in here I simply clone my repo and build my docker image and update build docker image id into kubernetes deployment manifest and deploy the pod. but I'm having trouble passing my build image id to next stage, I did some research and try to solve it so I managed to pass the id to next stage but when I try to add the new id to deployment manifests its empty.

here is my pipeline

pipeline {
  environment {
    BUILD_IMAGE_ID = ''
  }
  agent any
  stages {
    stage('Cloning Git') {
      steps {
      git( url: 'https://xxxxxx.git',
            credentialsId: 'id',
            branch: 'master')

      }
    }
  stage('Login Docker Registry') {
      steps{
        script {
            sh 'docker login --username=xxxx --password=xxxx registry.xxxx.com'
        }
      }
    }
    stage('Building Image') {
      steps{
         script {
         def IMAGE_ID = sh script:'docker run -e REPO_APP_BRANCH=xxxx -e REPO_APP_NAME=xxx --volume /var/run/docker.sock:/var/run/docker.sock registry.xxxx/image-build', returnStdout: true
         println "Build image id: ${IMAGE_ID} "
         BUILD_IMAGE_ID = IMAGE_ID.replace("/n","")
         env.BUILD_IMAGE_ID = BUILD_IMAGE_ID

        }
      }
    }

    stage('Integration'){
      steps{
        script{
          echo "passed: ${BUILD_IMAGE_ID} "
          //update deployment manifests with latest docker tag
          sh 'sed -i s,BUILD_ID,${BUILD_IMAGE_ID},g deployment-manifests/development/Service-deployments.yaml'



        }
      }
    }

  }
}

I don't want to save that value into a file and read and do the operation output

[Pipeline] echo
Build image id: 
 registry.xxxx.com/service:3426d51-baeffc2


[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Integration)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
passed: 
 registry.xxxx.com/service:3426d51-baeffc2


[Pipeline] sh
[orderservice] Running shell script
+ sed -i s,BUILD_ID,,g deployment-manifests/development/service-deployments.yaml
StephenKing
  • 36,187
  • 11
  • 83
  • 112
Jack
  • 1,162
  • 3
  • 12
  • 27
  • 1
    Possible duplicate of : https://stackoverflow.com/questions/44099851/how-do-i-pass-variables-between-stages-in-a-declarative-jenkins-pipeline – Gremi64 Oct 10 '18 at 10:05
  • 1
    Another solution here : https://serverfault.com/questions/884764/jenkins-pipeline-file-passing-jenkinsfile-variables-into-further-commands/884798 – Gremi64 Oct 10 '18 at 10:07
  • Yes, the second one.. – StephenKing Oct 11 '18 at 04:03

0 Answers0