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?
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.)
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: https://scriptrunner.adaptavist.com/latest/bitbucket/PreReceiveHooks.html#_custom_pre_receive_hooks
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
true
and
false
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michal,
Please also watch and/or vote for this issue for updates on the issue you have raised.
https://productsupport.adaptavist.com/browse/SRBITB-355
Kind regards,
Robert Giddings,
Product Manager, ScriptRunner for Bitbucket
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello!
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: https://promo.atlassian.com/3E1UXX
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.