we need to enforce developer to have Jira ticket in commit message

Vijay Kene February 2, 2018

We need to enforce developer to have Jira ticket in commit message. Current build in solution checks that either commit message OR feature branch has Jira. We need to check always commit message

Regardless what branch we push from local to remote – we want to check each commit message and verify that Jira is there
I have tried to use build in option “Require commits to be associated with a JIRA issue”

But this option check that Feature branch OR commit message has Jira. We need to check commit message always. I.e. - I don’t care what is the name of the branch but I want to know that commit has Jira.

We have tried to use other option called “Push check”. But it doesn’t work as well. Because when I commit with commit message having Jira (in proper state) it simply rejects it.

2 answers

0 votes
Julius Davies [bit-booster.com]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2018

 

We maintain an add-on, Control Freak for Bitbucket Server, that can help with this:

 

control-freak-jira-control.png

 

 

The free YACC add-on can also block commits that don't contain JIRA references in their commit message.

0 votes
adammarkham
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 2, 2018

Hi Vijay,

You could use the protect git references hook in ScriptRunner for Bitbucket Server for this.

If you just want to check the commit messages include a JIRA issue key in them you can use the following condition in that built-in pre-receive hook:

def commits = refChanges.getCommits(repository)

def issueKeyRegex = /((?<!([A-Z]{1,10})-?)[A-Z]+-\d+)/

commits.any { commit ->
!(commit.message =~ issueKeyRegex)
}

This will just check that the message contains a Jira issue key format, not that the issue actually exists in Jira which is what the "Require commits to be associated with a JIRA issue" hook does.

If you need that then it's a bit more complex.

Let us know how you get on with this and if you need something a bit different then feel free to ask.

Hope this helps.

Adam

Vijay Kene February 8, 2018

Hi Adam,

 Thanks for suggestion , I tried your suggested condition it is working fine only problem is - it will not validate the JIRA Issue key - means whether the Issue is Open or closed it accept the Issue key & commit - as it shouldn't allow commit if the Issue is closed , cancel , Resolved

 

Thanks,

Vijay

Like Vikram Kuruba likes this
Vijay Kene February 9, 2018

Hi Adam,

Can you please suggest ?

 

Thanks,

Vijay

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events