{"id":34430,"date":"2016-05-23T14:59:25","date_gmt":"2016-05-23T09:29:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=34430"},"modified":"2016-05-25T11:34:36","modified_gmt":"2016-05-25T06:04:36","slug":"setting-dynamic-project-description-and-build-description-in-jenkins","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/setting-dynamic-project-description-and-build-description-in-jenkins\/","title":{"rendered":"Setting Dynamic Project Description and Build Description in Jenkins"},"content":{"rendered":"<p>Jenkins is an open source tool designed to achieve <a title=\"continuous integration\" href=\"http:\/\/www.tothenew.com\/devops-chef-puppet-docker\">continuous integration<\/a> and continuous deployment.\u00a0I came across a scenario where I have to show custom results after every build run in Jenkins.\u00a0The 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.<\/p>\n<p>The job produces a tag based on the choice made by the user. The choice accepts either &#8216;Major&#8217;, &#8216;Minor&#8217; or &#8216;Fixed&#8217; change . Based on the choice made, the job produces new tag. For example, if the current tag is\u00a0<strong>4.0.0.\u00a0<\/strong>The new tag will be\u00a0<strong>5.0.0\u00a0<\/strong>if the choice made is &#8216;Major&#8217;,\u00a0<strong>4.1.0\u00a0<\/strong>if the choice made is minor and\u00a0<strong>4.0.1\u00a0<\/strong>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\u00a0tag, it is necessary to know the value of the\u00a0latest tag and the tags generated at various build results.<\/p>\n<p>I made use of\u00a0<strong>Dynamic Project Description\u00a0<\/strong>to show the value of the\u00a0latest tag and\u00a0<strong>Dynamic Build Description\u00a0<\/strong> 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.<\/p>\n<h3><span style=\"text-decoration: underline;\">Setting up Project Description<\/span><\/h3>\n<p>We will make use of\u00a0<strong>Project Description Setter Plugin\u00a0<\/strong>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:<\/p>\n<ol>\n<li>Go to\u00a0<strong>Manage Jenkins\u00a0<\/strong>option in Jenkins Console.<\/li>\n<li>Under &#8216;Manage Jenkins&#8217;, click on\u00a0<strong>Manage Plugins\u00a0<\/strong>option.<\/li>\n<li>Install\u00a0<strong>Project Description Setter Plugin.<\/strong><\/li>\n<li>After installing the plugin, configure your job. Go to your Jenkins job and click on\u00a0<strong>Configure.<\/strong><\/li>\n<li>Go under\u00a0<strong>Build Environment\u00a0<\/strong>and check on &#8216;Set a project description from a file in the workspace&#8217;.<\/li>\n<li>The file must be present in the workspace. The content of the file may include <b>Token Macros\u00a0<\/b>which will be expanded while setting up the description.<\/li>\n<\/ol>\n<p>The different kind of available tokens which can be used to set description are:<\/p>\n<ul>\n<li><strong>GIT_BRANCH :\u00a0<\/strong>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.<\/li>\n<li><strong>GIT_REVISION: <\/strong>It expands to the Git SHA1 commit ID that points to the commit that was built. It includes different parameters which could be used.<\/li>\n<li><strong>BUILD_CAUSE:\u00a0<\/strong>It will display the cause of the build.<\/li>\n<li><strong>BUILD_LOG_EXCERPT:\u00a0<\/strong>It is used to display a short extract from the build logs. You can use regex to filter the logs from starting or end.<\/li>\n<li><strong>BUILD_LOG:\u00a0<\/strong>It is used to display the end lines of the\u00a0build log.<\/li>\n<li><b>BUILD_ NUMBER:\u00a0<\/b>It is used to display the build number of the build.<\/li>\n<li><b>BUILD_STATUS:\u00a0<\/b>It is used to display the status of build e.g. failed, unstable or success etc.<\/li>\n<li><strong>JOB_DESCRIPTION:<\/strong> It will display the Job Description.<\/li>\n<li><strong>{FILE,path=&#8221;PATH&#8221;}:\u00a0<\/strong>It expands to the contents of a file. The\u00a0<strong>PATH<\/strong> is relative to the workspace of the job.<\/li>\n<li><strong>PROJECT_NAME:\u00a0<\/strong>It will display the Project name at Project Description.<\/li>\n<\/ul>\n<p>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:<\/p>\n<pre>${BUILD_LOG_REGEX,regex=\"The Latest Tag is (.*)\",showTruncatedLines=false}<\/pre>\n<p>The build log contains a\u00a0line for example, &#8221; The Latest Tag is v1.1.1.&#8221; So the project description will be set to this line.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-34639\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/05\/Jenkins-.png\" alt=\"Jenkins\" width=\"582\" height=\"250\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"text-decoration: underline;\">Setting up Build Description<\/span><\/h3>\n<p>We have learnt how to set up <strong>Project<\/strong><strong>\u00a0Description.<\/strong> Now we will study how to set up Build Description in Jenkins. The build description can be set by the following steps:<\/p>\n<ol>\n<li>\u00a0Go to\u00a0<strong>Manage Jenkins\u00a0<\/strong>option in Jenkins Console.<\/li>\n<li>Under &#8216;Manage Jenkins&#8217;, click on\u00a0<strong>Manage Plugins\u00a0<\/strong>option.<\/li>\n<li>Install\u00a0<strong>description setter<\/strong><strong>\u00a0Plugin.<\/strong><\/li>\n<li>After the plugin is installed, configure your job. Go to your Jenkins job and go to <strong>Post-build actions.<\/strong><\/li>\n<li>Click on\u00a0<strong>Set build description.<\/strong><\/li>\n<li>The new functionality will be setup as shown below:<\/li>\n<\/ol>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-34641\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/05\/Jenkins.png\" alt=\"Jenkins\" width=\"987\" height=\"307\" \/><\/p>\n<p>The Build Description will be set up for each build based on the regular expression. Enter the regular expression to set the description. The\u00a0<strong>Description\u00a0<\/strong>can be set for the build. The Regular expression can also be setup for failed builds. Here I have setup the description to\u00a0<strong>Failed\u00a0<\/strong>for failed jobs. Thus, the description will be set\u00a0<strong>Failed\u00a0<\/strong>whenever the build is failed.<\/p>\n<p>The given below is the example of setting\u00a0<strong>Dynamic Build Description\u00a0<\/strong>in\u00a0<strong>Jenkins:<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone  wp-image-34642\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/05\/Jenkins_failed.png\" alt=\"Jenkins_failed\" width=\"416\" height=\"260\" \/><\/p>\n<p>I will write more blogs on more\u00a0<strong>Advanced Techniques\u00a0<\/strong>on Jenkins. This blog has introduced how to set\u00a0<strong>Dynamic Project and Build Description\u00a0<\/strong>in\u00a0<strong>Jenkins.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jenkins is an open source tool designed to achieve continuous integration and continuous deployment.\u00a0I came across a scenario where I have to show custom results after every build run in Jenkins.\u00a0The build result produces dynamic values which are important to be identified before running the next build. For instance, I was creating a Jenkins job [&hellip;]<\/p>\n","protected":false},"author":163,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":370},"categories":[1174,2348],"tags":[3374,3373,3372,3376,3375,3378,3377],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/34430"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/163"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=34430"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/34430\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=34430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=34430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=34430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}