Semantic versioning for docker tag from Git tag

Define the version or build number is a very important step in a continuous integration and deployment pipeline.

When we build the docker image, we should add the version number as the tag to the image. And when we need deploy the docker image, we can refer the version number instead using latest tag.

Semantic versioning guideline is a widely used schema to define versions. In practice, how we generate the version number and keep the version number is still a challenge when we design a CI/CD pipeline to build docker images. In this post, I will introduce a method to generate version number from git tags and integrated with Jenkins and docker build.

The idea is to tag the git repo with a naming convention each time when we start a new build on release branch. The build job will check what is the version number of last build and increase the z value of x.y.z by 1. The build job will not change x or y value of the version number. There are 3 major steps in this process,

Check the current branch

We only generate the version number when we build on the release branch. So the first step is check what is current build branch.

READ THIS NEXT:

(continue.)
Tools and Plugins
Jenkins allows us to run all kind of jobs for automations as long as Jenkins can find the binaries, e.g. maven, ant, JDK.
challenges:
The installation path for each tool...