Setting Dynamic Project Description and Build Description in Jenkins
Jenkins is an open source tool designed to achieve continuous integration and continuous deployment. I came across a scenario where I have to show custom results after every build run in Jenkins. The build result produces dynamic values which are important to be identified before running the next build. For instance, I was creating a Jenkins job to create tags to the git repositories.
The job produces a tag based on the choice made by the user. The choice accepts either ‘Major’, ‘Minor’ or ‘Fixed’ change . Based on the choice made, the job produces new tag. For example, if the current tag is 4.0.0. The new tag will be 5.0.0 if the choice made is ‘Major’, 4.1.0 if the choice made is minor and 4.0.1 if the choice made is fixed. In a team, where a large number of people contribute and anyone can trigger the build to create the tag, it is necessary to know the value of the latest tag and the tags generated at various build results.
I made use of Dynamic Project Description to show the value of the latest tag and Dynamic Build Description to show the value of the tag generated at various build results. Jenkins uses various plugins to provide additional functionality to the users. Thus, we will make use of different plugins to use this feature.
Setting up Project Description
We will make use of Project Description Setter Plugin to set the project description after every build result. The file description is set using a file in the workspace. To set the description, follow the below steps:
- Go to Manage Jenkins option in Jenkins Console.
- Under ‘Manage Jenkins’, click on Manage Plugins option.
- Install Project Description Setter Plugin.
- After installing the plugin, configure your job. Go to your Jenkins job and click on Configure.
- Go under Build Environment and check on ‘Set a project description from a file in the workspace’.
- The file must be present in the workspace. The content of the file may include Token Macros which will be expanded while setting up the description.
The different kind of available tokens which can be used to set description are:
- GIT_BRANCH : it will be expanded to the branch name that was built. The ${GIT_BRANCH} variable wherever present in the file will be evaluated to its value.
- GIT_REVISION: It expands to the Git SHA1 commit ID that points to the commit that was built. It includes different parameters which could be used.
- BUILD_CAUSE: It will display the cause of the build.
- BUILD_LOG_EXCERPT: It is used to display a short extract from the build logs. You can use regex to filter the logs from starting or end.
- BUILD_LOG: It is used to display the end lines of the build log.
- BUILD_ NUMBER: It is used to display the build number of the build.
- BUILD_STATUS: It is used to display the status of build e.g. failed, unstable or success etc.
- JOB_DESCRIPTION: It will display the Job Description.
- {FILE,path=”PATH”}: It expands to the contents of a file. The PATH is relative to the workspace of the job.
- PROJECT_NAME: It will display the Project name at Project Description.
There are many other options which are available to get the project description. The following is the file content which I have used to set the description:
${BUILD_LOG_REGEX,regex="The Latest Tag is (.*)",showTruncatedLines=false}
The build log contains a line for example, ” The Latest Tag is v1.1.1.” So the project description will be set to this line.
Setting up Build Description
We have learnt how to set up Project Description. Now we will study how to set up Build Description in Jenkins. The build description can be set by the following steps:
- Go to Manage Jenkins option in Jenkins Console.
- Under ‘Manage Jenkins’, click on Manage Plugins option.
- Install description setter Plugin.
- After the plugin is installed, configure your job. Go to your Jenkins job and go to Post-build actions.
- Click on Set build description.
- The new functionality will be setup as shown below:
The Build Description will be set up for each build based on the regular expression. Enter the regular expression to set the description. The Description can be set for the build. The Regular expression can also be setup for failed builds. Here I have setup the description to Failed for failed jobs. Thus, the description will be set Failed whenever the build is failed.
The given below is the example of setting Dynamic Build Description in Jenkins:
I will write more blogs on more Advanced Techniques on Jenkins. This blog has introduced how to set Dynamic Project and Build Description in Jenkins.
Hi,
Above command is working fine for me. But i am getting in between 2 descriptions. Can you pls. help me how to remove this from my description output. And what i have to pass if need results one by one like below.
1
2
3
4
How can I set multiple descriptions, like regexs found on different lines?
Can I use environment variables with `description setter Plugin` plugin