I’m working with Bitbucket Data Center v9.4 that’s connected to our Jira instance. I need help setting up a hook that stops pull requests from being merged when the linked Jira ticket is blocked by other issues.
Right now I have Push check enabled in my project hooks with these settings:
- Issue key validation to ensure commits have valid ticket references
- JQL verification with this query:
status in ("To Do", "In Progress", "Code Review", "Done")
AND issue NOT IN linkedIssues($key, "blocked by")
AND issue NOT IN linkedIssues($key, "blocking")
The problem is this setup isn’t working. Pull requests still get merged even when the Jira ticket has blocking issues.
I also tried this alternative JQL in merge checks:
issue = "%key"
AND status in ("To Do", "In Progress", "Code Review", "Done")
AND NOT ( issueFunction in hasLinks("blocked by") OR issueFunction in hasLinks("blocking") )
This approach seems better but now I’m facing a different issue. The %key variable gets interpreted as [ABC-5678] with square brackets included, which breaks Jira searches. When using %branch instead, I get something like feature/ABC-5678.
I’ve tried various regex patterns like (?:.*/)([A-Z]+-\d+)(?/.*) and others but none work properly. Bitbucket can’t find the correct ticket because Jira searches fail with the bracketed format.
What’s the right way to configure this blocking validation? Is my JQL wrong or do I need different hook settings?
I’ve dealt with this same headache. Yeah, the square brackets are a pain, but you can skip them entirely by using pre-receive hooks instead of merge checks. Try this JQL: project = "YOURPROJECT" AND issueFunction in linkedIssuesOf("%key", "blocks") AND resolution is EMPTY - it’ll catch any unresolved blocking tickets. One more thing - make sure your Bitbucket admin actually turned on the advanced JQL functions. Half the time they’re disabled by default.
I’ve hit this exact issue with Bitbucket hooks and Jira integration. The %key variable including brackets is a known Bitbucket quirk. Skip the regex approach - there’s a cleaner way.
Try this JQL structure instead: key = %key AND status in ("To Do", "In Progress", "Code Review", "Done") AND issueFunction not in hasLinks("is blocked by"). Use key = %key directly, not issue = "%key". Jira’s parser handles the brackets much better this way.
Also, make sure you’re using “is blocked by” for the link type - might be different in your setup. If it’s still not working, double-check your Jira issue link config. Sometimes they’re set up as “Blocks/Blocked by” or “Dependencies” instead of the standard names.
Your linkedIssues function should work, but there’s a syntax issue. You need to reference the current issue properly. Try linkedIssues(%key, "is blocked by") is EMPTY instead of the NOT IN structure. For the %key bracket problem, I’ve had better luck using merge checks instead of push checks. Merge checks run after PR creation but before merging, so they get better access to the actual issue data. Also double-check your Jira link type names. Run a test query directly in Jira with your actual ticket number to confirm the exact relationship names. Some instances use “depends on” or “has dependency” instead of “blocked by”. The JQL functions are case-sensitive and must match your Jira workflow exactly.