Creating a Bitbucket JIRA pre-hook to verify commit messages

I’m trying to set up a pre-hook in Bitbucket to make sure all commit messages include a JIRA issue number. But I’m stuck on the JQL query part.

When I try to save the hook, it asks for a valid JQL query to match the issues I want. The thing is, I want it to match any JIRA issue at all. I’m not looking to filter for specific projects or issue types.

Does anyone know how to write a JQL query that will basically say ‘match everything’? I’ve tried a few things but keep getting errors.

I’m new to JQL and could really use some help figuring out the right syntax for this. Thanks in advance for any tips or examples you can share!

As someone who’s implemented similar hooks before, I can tell you that the JQL query ‘issue is not EMPTY’ is indeed a good starting point. However, in practice, I’ve found it can be quite slow on larger JIRA instances.

A more efficient approach I’ve used is to combine project filtering with a wildcard search. Something like: ‘project in (PROJ1, PROJ2) AND issue ~ “*”’

This narrows down the scope while still matching any issue within those projects. You can adjust the project list as needed.

One gotcha to watch out for: make sure your Bitbucket service account has the necessary permissions in JIRA. I once spent hours debugging a hook only to realize it was a simple permissions issue.

Lastly, consider implementing some local caching mechanism if you’re dealing with a high volume of commits. It can significantly reduce the load on your JIRA instance and speed up the commit process for your devs.

For a JQL query that matches all issues, you can simply use ‘issue is not EMPTY’. This will return every issue in your JIRA instance, regardless of project or type.

However, for performance reasons, it’s often better to limit the scope somewhat. You could use ‘project in (proj1, proj2, proj3)’ to include only relevant projects, or ‘created > -30d’ to match issues created in the last 30 days.

If you’re still having trouble, double-check your Bitbucket permissions. Sometimes, JQL queries fail not because of syntax, but because the hook doesn’t have sufficient access to run queries against JIRA.

Lastly, consider implementing the check in a pre-receive hook on the server side instead. This gives you more control and can be more reliable than client-side pre-commit hooks.

hey, i’ve used jql and for matching everything, try ‘issuekey is not null’. works well if ur bitbucket has permissions for jira. maybe add ‘updated > -60d’ to filter and boost performance. good luck with ur hook!