'Use same docker image tag in two different jenkins pipeline

I have 2 jenkins pipelines, in one pipeline I am building image and pushing image to docker registry. I am using BUILD_NUMBER for tagging the new build image.

dockerImage = docker.build("springboot:${BUILD_NUMBER}")
dockerImage.push()

In the second pipeline, I am using sshagent plugin to login into host machines and running docker pull command to pull the same image that I build and push in first pipeline above.

sshagent(['aws-private-access-key']){
     sh "ssh -o StrictHostKeyChecking=no [email protected] docker pull 
     springboot:${BUILD_NUMBER}"
}

Problem with the second pipeline is that, the BUILD_NUMBER for both pipeline can be different from each others, and when I run second pipeline it is not able to pull the image because tag of docker image in registry differs from the current BUILD_NUMBER.

I am looking for a solution how this can be solved. I know "latest" tag but I want to keep my images versions with proper tagging.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source