Hello,
my company uses
- Atlassian Jira Server 9.12.4 and
- Atlassian Bitbucket Server 8.9.10 with
- Adaptavist ScriptRunner for Bitbucket 8.19.0.
With the help of the ScriptRunner pre-hook "Require commits to be associated with a valid Jira issue", I want to ensure that very certain branches (feature/, bugfix/ or hotfix/ with -bbb- in the following name) can only be created in our Git repository in case the corresponding Jira ticket is of the type Defect or Story. It is fine to check this only for new branches and not for any legacy ones which are already part of the repository.
The hook that I have created works like a charm in case the branches to be checked are created locally and then pushed either via CLI or any local Git client.
However, when creating branches right from a Jira ticket, the hook does not seem to work.
Other ScriptRunner pre-hooks, like "Branch and tag naming standards enforcement", that we use to generally ensure proper branch names, also work when branches are created from a Jira ticket (veto/error message is shown in Jira UI). My assumption is, that while the "Branch and tag naming standards enforcement" pre-hook simply checks against a regex, the "Require commits to be associated with a valid Jira issue" pre-hook additionally establishes the connection to Jira what might end up in a race condition-like behavior (but again, that's just a guess).
Does anybody have a clue why the "Require commits to be associated with a valid Jira issue" pre-hook does not work when the branches are created from a Jira ticket (and how to solve it)?
Please see the config of the affected hook below:
Condition:
// block git push of new branches if they are proper BBB source branches
// (short-living and "-bbb-" in the name) but the corresponding ticket is not
// of the expected type (as per the JQL clause below)
import com.atlassian.bitbucket.repository.RefChangeType
refChanges.any {
it.type == RefChangeType.ADD && it.ref.displayId.matches(/^(feature|bugfix|hotfix)\/\S+?-bbb-\S+$/)
}
JQL clause template:
type in (Story, Defect)
Thanks and best regards
Sascha