{"id":5249,"date":"2018-08-22T14:21:59","date_gmt":"2018-08-22T14:21:59","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5249"},"modified":"2021-11-17T10:14:30","modified_gmt":"2021-11-17T10:14:30","slug":"enforce-the-jira-issue-id-in-a-git-commit-message","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/enforce-the-jira-issue-id-in-a-git-commit-message\/","title":{"rendered":"Enforce the JIRA issue id in a GIT commit message"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5258\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2018\/08\/jira-git.png\" alt=\"\" width=\"600\" height=\"350\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/08\/jira-git.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2018\/08\/jira-git-300x175.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Enforce the JIRA issue id in a GIT commit message<\/p>\n<p><strong>This can be done by using git hooks file location at .git\/hooks\/commit-msg<\/strong>. Following are the 2 way in whcih each Developers can set the Hooks in their developement envioronment.<\/p>\n<p><strong>Method &#8211; 1<\/strong><\/p>\n<p>[code]# commit-msg.sh<br>\n#!\/bin\/sh<br>\n# This hook will make sure that the commit message contains a JIRA issue.<br>\n#<br>\n# To enable this hook, rename this file to &#8220;.git\/hooks\/commit-msg&#8221;.<br>\n# Make sure to add execution permissions to the file.<\/p>\n<p>export MESSAGE=$(&lt;$1)<br>\nexport JIRA_ISSUE_TAG=&#8217;ISSUETAG-([0-9]*)&#8217;<\/p>\n<p>if [[ $MESSAGE =~ $JIRA_ISSUE_TAG ]]; then<br>\necho -e &#8220;\\e[32mGreat, your commit message contains a JIRA issue!\\e[0m&#8221;<br>\nexit 0;<br>\nfi<\/p>\n<p>echo -e &#8220;\\e[31mOh hamburgers &#8230; You forgot to add a JIRA issue number!\\e[0m&#8221;;<br>\nexit 1;<\/p>\n<p>[\/code]<\/p>\n<p><strong>Method 2 &#8211;<\/strong> This is another very good example to implement to force jira id in each commit message. http:\/\/nsbogan.com\/tools\/2015\/06\/04\/jira-id-in-git-commit-messages<\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_59443\"><figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube epyt-figure\"><div class=\"wp-block-embed__wrapper\"><iframe loading=\"lazy\"  id=\"_ytid_47543\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_59443\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Enforce the JIRA issue id in a GIT commit message This can be done by using git hooks file location at .git\/hooks\/commit-msg. Following are the 2 way in whcih each Developers can set the Hooks in their developement envioronment. Method &#8211; 1 [code]# commit-msg.sh #!\/bin\/sh # This hook will make sure that the commit message&#8230;<\/p>\n","protected":false},"author":1,"featured_media":5258,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5106],"tags":[5023,5031,945,160,595],"class_list":["post-5249","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jira","tag-commit","tag-commit-msg","tag-gerrit","tag-git","tag-jira"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=5249"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5249\/revisions"}],"predecessor-version":[{"id":25587,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5249\/revisions\/25587"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/5258"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=5249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=5249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=5249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}