Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Pre-Hook for Comits to have JIRA IDs when branch name contains JIRA ID as well

Hey Guys,

I have tried to implement pre-hook by Scriptrunner in bitbucket - "Require commits to be associated with a JIRA issue" . 

Goal is to achieve that every commit before pushing will contain the JIRA ID

Problem - In the name of branches I use related JIRA Ticket ID, by the conditon in this defined pre-hook"The issue can either be mentioned in the commit message, or be present in the branch name"

I tried using conditions but so far I wasn't able to fix this, could anyone help me in this please?

4 answers


I'm part of Reconquest team, which is developing External Hooks Add-on for
Bitbucket Server/Data Center.

You can implement enforcing Jira ID reference in the commit message by writing
a script for our plugin using any language of your choice.

We've prepared a quick guide on how to do it using bash, just for you.

By the way, here is 25% discount link for External Hooks Add-on:

Thank you Stanislav for you answer, unfortunately I won't be able to introduce any plugin in the company which I work. 


I wanted to check in condition basically if this commit message follow JIRA Regexp and found code like that:

def commits = refChanges.getCommits(repository)

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

if( commits.any { commit ->
!(commit.message =~ issueKeyRegex)
return true
return false

 Still no progress :(

Hi Michal,

The condition block for a pre-defined Pre-Hook such as "Require commits to be associated with a JIRA issue", is used to determine which changes the hook applies to.

I therefore suggest you create a Custom Pre-Hook.

In order to create a Custom Pre-Hook for your needs, please use the Custom Pre-Hook functionality, outlined in the docs here:

You then should be able to add your code above to the inline script field of the Custom Pre-Hook.

However, I think you want to swap the




statements around, as false blocks the push and true allows it.

See the documentation for details.

Please let me know if this resolves your issue?

I am also going to see if we can improve the built in "Require commits to be associated with a JIRA issue" pre-hook for a future release of ScriptRunner.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Hi Michal,

Please also watch and/or vote for this issue for updates on the issue you have raised.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

0 votes

You can use the Better Commit Policy for Bitbucket app for these type of use cases. (It is an app that adapts the Better Commit Policy for Jira app to Bitbucket.)

It can verify commit messages for issue keys, verify branch names for issue keys, even do that selectively with scope limiting.

One of the best things is that it will suggest you the most likely issue keys you want to enter like this:

remote: ========================================================================
remote:                                REJECTED!
remote: ========================================================================
remote: 1.1 COMMIT [6ecb44a] on [master] Exactly one issue key must be mentioned in the commit message "Guard against the NullPointerException"
remote: ========================================================================
remote: Did you mean one of these issues?
remote: [FOO-82] Crash when submitting the form using Safari
remote: [FOO-27] Keyboard shortcuts
remote: [FOO-11] As a user, I want to choose my own language for the app
remote: ========================================================================

So you can make it very convenient for the developer.

(Disclaimer: I am developer working on this paid app.)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

442 views 4 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you