Hello, dear community,
I am using Bitbucket Data Center version 9.4.
My Bitbucket Data Center is directly integrated with my Jira.
Currently, I want to configure it so that when a pull request is created, Bitbucket checks the Jira ticket associated with the pull request, and if that ticket contains information that it is blocked by another issue, Bitbucket will not allow merging the code with the main branch until the blockers are resolved.
At the moment, I have applied the following configuration:
In the settings of my Bitbucket project, under Hooks, I enabled the Push check parameter.
Within the Push check parameter, I enabled:
- Issue-Key checks - At least one commit must contain a valid issue key.
- JQL check - At least one issue reference must match the given JQL, and I set the following query:
<span>status <span>in</span> <span>(<span>"In Progress"</span>, <span>"Open"</span>, <span>"In Review"</span>, <span>"Resolved"</span>)</span><br>AND issue NOT IN <span>linkedIssues</span><span>($key, <span>"is blocked by"</span>)</span><br>AND issue NOT IN <span>linkedIssues</span><span>($key, <span>"blocks"</span>)</span> </span>
Unfortunately, my configuration is not working; I can merge a pull request with the main branch even if the Jira ticket has a blocker from another ticket.
Perhaps I am using the wrong query? Or maybe the options for the Push check parameter are not correct for my task?
Please help me figure this out.
UPDATE:
As is the other example that I used in merge checks section while conducting my investigation. This approach is also correct:
issue = "%key" AND status in ("In Progress", "Open", "In Review", "Resolved") AND NOT ( issueFunction in hasLinks("is blocked by") OR issueFunction in hasLinks("blocks") )
But now I've encountered another problem: for reasons unclear to me, the %key value in Bitbucket is interpreted as [FUI-1234]—in other words, it inserts the square brackets, even though I don’t use them anywhere. If I try to extract the key from the branch instead of the commit, the %branch value is extracted as bugfix/FUI-1234. I have tried many issue key regular expressions, for example, (?:./)?([A-Z]+-\d+)(?:/.)? and (?<=^|[a-z]-|[\s\p{Punct}&&[^-]])(?!FUI-)([A-Z][A-Z0-9_]*-\d+)(?![^\W_]), but none of them work. It turns out that Bitbucket simply cannot find the correct ticket in Jira because it is impossible to perform a search in Jira using square brackets.