Zorthgo
Zorthgo

Reputation: 2977

JIRA smart commit - Block git commit without JIRA ticket number

I am trying to block a GIT commit if the commit message doesn't include a JIRA ticket number. Has anyone been able to do this?

From my understanding the following commit message will log the commit message on ticket WEBSITE-4.

JIRA:WEBSITE-4 #comment Testing smart commit.

But I need a way to block the commit from happening whenever the user forgets to include JIRA:<ticket number> in the commit message.

Upvotes: 1

Views: 6079

Answers (2)

VonC
VonC

Reputation: 1325137

If you have your own Bitbucket server, you can add a plugin like "Yet Another Commit Checker" which does precisely that:

Yet Another Commit Checker is a Stash plugin that allows you to reject commits to a repository based on configurable rules. Its main feature is requiring commit messages to contain a valid JIRA issue,

See its GitHub repo.

If not, as discussed here, you need a pre-commit hook (client side) or a pre-receive hook (but for a public BitBucket server, that would mean a webhook) See "Hooked on Stash".


The "Require issue keys in commit messages" mentioned here has been introduced for BiBucket Cloud in May 2017

This thread adds:

As long as you setup your links under repository settings to hook with JIRA, you do NOT HAVE TO switch on "Require issue keys in commit messages" under Bitbucket Repository -> Settings -> Links.
That is basically a rule you are setting that no one can push anything without issue keys. If you want to disable temporarily, then you can switch it off and on any time.

As mentioned here:

Bitbucket Server does not have the same option to require issue keys in commit comments out-of-the-box.
You would have to get an app (like Jira hooks for Bitbucket or Better commit policy for Bitbucket) or write your own in order to get that functionality.
Or:

Upvotes: 3

A. Novice
A. Novice

Reputation: 21

on the Bitbucket cloud

  1. go to your Bitbucket repo -> settings -> Links
  2. turn on the "Require issue keys in commit messages"

Upvotes: 2

Related Questions