11

The exact need is to force all commits into Bitbucket to be linked to a JIRA ticket.

I have does this before on Subversion by creating a commit hook that looked for the JIRA ticket in the commit text, but I don't want this solution to be necessarily constrained to that prior experience.

Does Bitbucket have a setting somewhere to force association for all commits against Jira tickets? If not - does it have a mechanism for enforce commit comment quality (some sort of hook or regex)? If not - does GIT have something that we can use for this purpose?

The imagined solution is (but not limited to being) a commit hook that fails the commit if the comment text does not contain a leading JIRA ticket, followed by a colon, followed by some commit text, such that:

git commit -m "foo"

fails and

git commit -m "PRJ-9327: foo"

commits...

Inquisitor Shm
  • 1,433
  • 5
  • 17
  • 26
  • The feature is out of beta now (https://bitbucket.org/site/master/issues/5658/option-to-reject-commits-without-an-issue#comment-35965158): I have edited the answer to reflect that. – VonC Apr 14 '17 at 06:46
  • By the way, it is "Jira", not "JIRA". "Jira" is not an acronym. – mhck Jun 28 '23 at 18:35

2 Answers2

10

The BitBucket issue 5658 just got implemented today (April 13th, 2017)

Option to reject commits without an issue key in their message

This feature is now available to all users via the repository settings "links" page

The pre-receive hook that rejects pushes when any commit does not have a valid issue key in its message.
The current implementation relies on the per-repository "Links" setting to determine what a valid issue key looks like. This gives us the ability to validate against Jira, Bitbucket Issues, Connect add-ons, and any configured custom Links.

So you don't need for a third-party plugin anymore.

Link

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Update (14 April 2017)

It looks like this feature has been integrated to the JIRA mainline and should be released soon. See VonC's answer for details.

Original answer

There is a number of plugins for Bitbucket that can do this. For example Commit Policy Plugin for Bitbucket (free)

Disclosure: I'm not in any way connected to the team behind the plugin I mentioned.

jannis
  • 4,843
  • 1
  • 23
  • 53