Reputation: 151
I am creating a Jenkins pipeline for building multiple microservices and to create docker images and push them to a private Docker registry.
The docker images are created via Gradle build via docker plugin and I am even able to push the images.
I need help with the following questions.
Upvotes: 0
Views: 2320
Reputation: 813
Use %BUILD_NUMBER% in windows and ${BUILD_NUMBER} in linux
You can do like mentioned below. eg: docker build -t image-name:%BUILD_NUMBER%
Upvotes: 1
Reputation: 151
Basically, Jenkins exposes BUILD_NUMBER env variable, we can simply read it in the gradle file like below and use the same to name the docker images
buildscript {
ext {
springBootVersion = "2.1.3.RELEASE"
dependencyManagementVersion = "1.0.7.RELEASE"
gradleDockerVersion = "0.13.0"
spotBugsVersion = "1.7.1"
guavaVersion = "27.0.1-jre"
nodeVersion = "1.3.1"
buildNumber = System.getenv("BUILD_NUMBER")!=null? System.getenv("BUILD_NUMBER") : "latest"
}
.....
.....
.....
}
Upvotes: 0
Reputation: 2477
1- For the tagging purpose you can use jenkin environment variables like BUILD_NUMBER
For detail check following link : https://wiki.jenkins.io/display/JENKINS/Building+a+software+project
2- For maintaining max number of images that you want to hold in the docker registry depends on the provider.
For example : Artifactory from jFrog
https://www.jfrog.com/confluence/display/RTF/Docker+Registry
Set Max Unique Tags. This specifies the maximum number of unique tags, per repository, that should be stored for a Docker image. Once the number of tags for an image exceeds this number, older tags will be removed. Leaving the field blank (default) means all tags will be stored.
Upvotes: 0