In this page
Execute automation rule only in repository A and B
Execute automation rule only for branch A and B
Execute automation rule only for committer A and B
Execute automation rule only in directory A and B
Execute automation rule only for file A and B
Conditional executions
When implementing automation rules, you may want to run some of those with limited scope: only in a subset of your repositories or only for a subset of your branches, for example. These scopes can be easily implemented using the Advanced Compare Condition in the rule:
For more complicated decisions you can check issue fields and attachments, filter issues with JQL or create if-else switches using other condition types.
The following sections give step-by-step guides to the most frequent conditional situations. They assume that there is an already working automation rule that you want to make conditional now.
Please note that even if the condition evaluates to false and the execution ends, there is a new entry with the "NO ACTIONS PERFORMED" result added to the audit log. This is actually helpful as it indicates that the rule was triggered (and ended) as expected.
Execute automation rule only in repository A and B
The idea is to insert an Advanced compare condition block before your action in the rule. The condition matches a regular expression to the repository ID, counts the matches, and continues the execution only if there is at least one match.
Steps:
- Edit your automation rule.
- Move your mouse between the trigger and the action on the left, and click Add component.
- Click New condition, and select Advanced compare condition.
-
Enter one of these expressions to the First value field:
## Bitbucket: in the original (non-fork) repositories only {{changesetHelper.matchRepository(devops.changeset,"[^~]+").size}} ## in the "foo" repository only {{changesetHelper.matchRepository(devops.changeset,".*[\\\/]foo(.git)?").size}} ## in two specific repositories {{changesetHelper.matchRepository(devops.changeset,".*[\\\/](repo-a|repo-b)(.git)?").size}} ## in all repositories whose name contains android {{changesetHelper.matchRepository(devops.changeset,".*android.*").size}} ## the same checks work for commits, too (in case of the Genius Commit Created trigger) {{changesetHelper.matchRepository(devops.commit,".*[\\\/]foo(.git)?").size}}
Notes:- You can use regular expressions as the matcher patterns in green. Don't forget the "\" escaping character before the "/" character!
- Choose the does not equal option from the Condition dropdown.
- Enter "0" in the Second value field.
- Click Save, then Publish changes.
How to find out the repository ID?
The repository ID is a unique identifier of a repository. It uses a proprietary format which depends on the computer that hosts the repository, on the repository URL and on the repository location. It may not be very intuitive for the first sight, therefore here is a guide to figure this out.
The idea is to create an automation action that writes the repository ID to the rule audit log when a changeset is accepted. You can then go to the audit log and see the repository ID there.
Steps:
- Login to Jira as admin, go to Administration → System → Automation rules.
- Click Create rule.
- Select the trigger Changeset accepted (from the DevOps category).
- Click Save.
- Click New action.
- Select the action Log action.
- Enter {{devops.changeset.repositoryId}} in the Log message field.
- Click Save.
- Name your automation rule intuitively, and click Turn it on.
- Create an arbitrary commit.
- Go to the Audit log screen of the rule.
- Click the Show more link of the latest execution on the right.
-
The repository ID is shown with green background color:
- Remote repositories: it is the repository URL like http://admin@localhost:7990/scm/my-project/myrepo.git
- Local repositories: it is in the format "hostname:repository location" like DESKTOP-Q3395CE:d:\my-project\myrepo
- If you gave the rule an intuitive name like "Log repository ID", then you could just disable it and keep it for future use. (If you are sure that you won't need it anymore, you could now delete the rule, as its only purpose was to find out the repository ID.)
Please note that, because you are typically hosting all your repositories on the same server, only that fragment of the ID that depends on the repository name will be varying.
Execute automation rule only for branch A and B
The idea is to insert an Advanced compare condition block before your action in the rule. The condition matches a regular expression to the branch name, counts the matches, and continues the execution only if there is at least one match.
Steps:
- Edit your automation rule.
- Move your mouse between the trigger and the action on the left, and click Add component.
- Click New condition, and select Advanced compare condition.
-
Enter one of these expressions to the First value field:
## for the "master" branch only {{changesetHelper.matchBranches(devops.changeset,"master").size}} ## for two specific branches {{changesetHelper.matchBranches(devops.changeset,"(branch-a|branch-b)").size}} ## for all feature branches {{changesetHelper.matchBranches(devops.changeset,"feature\/.*").size}}
Notes:- If you are using the Genius Commit created trigger, replace devops.changeset with devops.commit in the expressions above.
- You can use regular expressions as the matcher patterns in green. Don't forget the "\" escaping character before the "/" character!
- Choose the does not equal option from the Condition dropdown.
- Enter "0" in the Second value field.
- Click Save, then Publish changes.
Execute automation rule only for committer A and B
The idea is to insert an Advanced compare condition block before your action in the rule. The condition matches a regular expression to the committer name, counts the matches, and continues the execution only if there is at least one match.
Steps:
- Edit your automation rule.
- Move your mouse between the trigger and the action on the left, and click Add component.
- Click New condition, and select Advanced compare condition.
-
Enter one of these expressions to the First value field:
## for "alice" only {{changesetHelper.matchCommitters(devops.changeset,"alice").size}} ## for "alice" and "bob" only {{changesetHelper.matchCommitters(devops.changeset,"(alice|bob)").size}} ## for all users whose name starts with "ext-" {{changesetHelper.matchCommitters(devops.changeset,"ext-.*").size}}
Notes:- If you are using the Genius Commit created trigger, replace devops.changeset with devops.commit in the expressions above.
- You can use regular expressions as the matcher patterns in green.
- Choose the does not equal option from the Condition dropdown.
- Enter "0" in the Second value field.
- Click Save, then Publish changes.
Execute automation rule only in directory A and B
The idea is to insert an Advanced compare condition block before your action in the rule. The condition matches a regular expression to the changed file paths, counts the matches, and continues the execution only if there is at least one match.
Steps:
- Edit your automation rule.
- Move your mouse between the trigger and the action on the left, and click Add component.
- Click New condition, and select Advanced compare condition.
-
Enter one of these expressions to the First value field:
## for the "src" directory only {{changesetHelper.matchPaths(devops.changeset,"src\/.*").size}} ## for the "src" and "test/java" directories only {{changesetHelper.matchPaths(devops.changeset,"(src\/.*|test\/java\/.*)").size}} ## for file modifications in the "test/java" directory {{changesetHelper.matchPaths(devops.changeset,"test\/java\/.*", "m").size}} ## for file additions or deletions in any directory (note the argument "a,d"!) {{changesetHelper.matchPaths(devops.changeset,".*", "a,d").size}}
Notes:- If you are using the Genius Commit created trigger, replace devops.changeset with devops.commit in the expressions above.
- You can use regular expressions as the matcher patterns in green. Don't forget the "\" escaping character before the "/" character!
- For available values of actions, see the action codes for files in the smart value reference table.
- Choose the does not equal option from the Condition dropdown.
- Enter "0" in the Second value field.
- Click Save, then Publish changes.
Execute automation rule only for file A and B
Follow the instructions in the execute rule only in directory A and B recipe above, with the only difference of using a regular expression in step 4 that matches file names instead of directories:
## for the "build.xml" file only {{changesetHelper.matchPaths(devops.changeset,"build\.xml").size}} ## for the "pom.xml" and "img/logo.jpg" files only {{changesetHelper.matchPaths(devops.changeset,"(pom\.xml|img\/logo\.jpg)").size}} ## for all Java files {{changesetHelper.matchPaths(devops.changeset,"(.*\.java)").size}} ## for the deletion of any Java file (note the argument "d"!) {{changesetHelper.matchPaths(devops.changeset,"(.*\.java)","d").size}}
Questions?
Ask us any time.