Automation rule to add multiple users to multiple groups identified from Jira issue
Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.
Summary
A customer requested a solution to automatically add multiple users listed in a Jira issue to multiple groups, also specified in the same issue. However, Jira Automation's current branching feature does not support iterating over both users and groups simultaneously. To implement this, two Automation rules were developed to meet the requirements through webhook-based integrations.
Environment
- Jira Cloud
- Automation: Automation for Jira(A4J)
- Custom Fields:
customfield_10104
: Contains the user information.customfield_10108
: Contains the group information.
Diagnosis
- Jira Automation allows branching based on smart values for either users or groups, but it does not support nested iterations (branching) for processing multiple users and groups simultaneously.
- A workaround was identified using webhooks to retrieve group information and associate it with user account IDs.
Cause
The current limitation in Jira Automation prevents the use of nested branches to process both users and groups simultaneously. This meant that a standard rule couldn't handle the customer's requirement to add multiple users to multiple groups directly.
Solution
Rule 1: To identify the users and group
First, import the Automation rule
{
"cloud": true,
"rules": [
{
"id": 21067571,
"clientKey": "466b9777-4c4a-3815-bc3a-43dfc2f50896",
"name": "web Add multi user to group (V4) - modified ",
"state": "DISABLED",
"description": "",
"authorAccountId": "63da235ffb75f8568f5f6e38",
"actor": {
"type": "ACCOUNT_ID",
"value": "557058:f58131cb-b67d-43c7-b30d-6b58d40bd077"
},
"created": 1723475883144,
"updated": 1723537377851,
"trigger": {
"id": "562970758",
"component": "TRIGGER",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 3,
"type": "jira.manual.trigger.issue",
"value": {
"inputFromUsers": false,
"inputPrompts": [],
"groupIds": true,
"groups": [],
"issueFilter": null,
"jQLFilter": null
},
"children": [],
"conditions": [],
"connectionId": null
},
"components": [
{
"id": "562970759",
"component": "CONDITION",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.comparator.condition",
"value": {
"first": "{{issue.customfield_10104}}",
"second": "",
"operator": "NOT_EQUALS"
},
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970761",
"component": "ACTION",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "user is {{issue.fields.customfield_10104}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970763",
"component": "CONDITION",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.comparator.condition",
"value": {
"first": "{{issue.fields.customfield_10108}}",
"second": "",
"operator": "NOT_EQUALS"
},
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970765",
"component": "ACTION",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "{{issue.fields.customfield_10108.value.replace(\" \", \"+\")}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970767",
"component": "BRANCH",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.smart.values.branch",
"value": {
"id": "_customsmartvalue_id_1722437278926",
"name": {
"type": "FREE",
"value": "name"
},
"type": "SMART",
"query": {
"type": "SMART",
"value": "{{issue.fields.customfield_10108.value.replace(\" \", \"+\")}}"
},
"lazy": false
},
"children": [
{
"id": "562970769",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "the taken value is {{name}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970772",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.issue.outgoing.webhook",
"value": {
"url": "https://atl-test-rhameed2.atlassian.net/rest/api/3/group?groupname={{name}}",
"headers": [
{
"id": "_header_1722437089632",
"name": "",
"value": "",
"headerSecure": false
},
{
"id": "_header_1722437185678",
"name": "Authorization",
"value": "Basic cmhhbWVlZDJAYXRsYXNzaWFuLmNvbTpBVEFUVDN4RmZHRjBkaS1xejgzLTBHSmJBclFDdWJiQ0tHVDJXYUVXWE9XTEtveFhVR3A3WkV0a1lDeHlESm0xV1pINEdkVVhCaWxTOUhLT29heGp6LXdoMUQzRmFDdGxBdm1BMGkxcTA1dGtYdW1yVDZHOWRYSGs0YWJCaUJkNGIwbFJIOG1tTWF4NnpyM1l0QW5XUkRyd1FwckQ3WVZvcVdKSTFXZVAtTkx6NFdCSXpOTFc5aTA9NzI5QjJGMDU=",
"headerSecure": false
}
],
"sendIssue": false,
"contentType": "empty",
"customBody": "",
"method": "GET",
"responseEnabled": true,
"continueOnErrorEnabled": true
},
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970775",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.create.variable",
"value": {
"id": "_customsmartvalue_id_1723525036103",
"name": {
"type": "FREE",
"value": "groupidlist"
},
"type": "SMART",
"query": {
"type": "SMART",
"value": "{{webhookResponse.body.groupId}}"
},
"lazy": false
},
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970780",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "id are: {{webhookResponse.body.groupId}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970785",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "group ID's are: {{groupidlist}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970792",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "JSON: {{issue.customfield_10104.asJsonObjectArray(\"accountId\")}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970795",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.create.variable",
"value": {
"id": "_customsmartvalue_id_1723531586144",
"name": {
"type": "FREE",
"value": "accid"
},
"type": "SMART",
"query": {
"type": "SMART",
"value": "{{issue.customfield_10104.asJsonObjectArray(\"accountId\")}}"
},
"lazy": false
},
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970799",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "accid: {{accid.remove(\"[\").remove(\"]\").replace(\"},{\",\",\")}}",
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970801",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.issue.outgoing.webhook",
"value": {
"url": "https://automation.atlassian.com/pro/hooks/c15981023fbd6ef7fc3ad70f2eb1bf05e15092fb?issue={{triggerissue}}",
"headers": [
{
"id": "_header_1723533045692",
"name": "",
"value": "",
"headerSecure": false
}
],
"sendIssue": false,
"contentType": "custom",
"customBody": "{\n \"issue\": {\n \"key\": \"{{triggerissue}}\",\n \"user\" : {{accid}},\n \"group\" : \"{{groupidlist}}\"\n }\n}",
"method": "POST",
"responseEnabled": true,
"continueOnErrorEnabled": false
},
"children": [],
"conditions": [],
"connectionId": null
},
{
"id": "562970802",
"component": "ACTION",
"parentId": "562970767",
"conditionParentId": null,
"schemaVersion": 1,
"type": "jira.issue.outgoing.webhook",
"value": {
"url": "https://webhook.site/85ea8944-4de2-4bf2-94de-5da1ee6959ad?issue={{triggerissue}}",
"headers": [
{
"id": "_header_1723533045692",
"name": "",
"value": "",
"headerSecure": false
}
],
"sendIssue": false,
"contentType": "custom",
"customBody": "{\n \"issue\": {\n \"key\": \"{{triggerissue}}\",\n \"user\" : \"{{accid}}\",\n \"group\" : \"{{groupidlist}}\"\n }\n}",
"method": "POST",
"responseEnabled": true,
"continueOnErrorEnabled": false
},
"children": [],
"conditions": [],
"connectionId": null
}
],
"conditions": [],
"connectionId": null
},
{
"id": "562970803",
"component": "ACTION",
"parentId": null,
"conditionParentId": null,
"schemaVersion": 1,
"type": "codebarrel.action.log",
"value": "{{groupidlist}}",
"children": [],
"conditions": [],
"connectionId": null
}
],
"canOtherRuleTrigger": false,
"notifyOnError": "FIRSTERROR",
"projects": [],
"labels": [],
"tags": [
{
"id": 83590806,
"ruleIdUuid": null,
"tagType": "IS_RULE_UPDATED",
"tagValue": "true"
}
],
"ruleScope": {
"resources": [
"ari:cloud:jira:be8a4606-6804-4215-b486-6b0057e1fa6f:project/10001"
]
},
"ruleHome": {
"ruleLifecycleHome": {
"locationARI": "ari:cloud:jira:be8a4606-6804-4215-b486-6b0057e1fa6f:project/10001"
},
"ruleBillingHome": {
"locationARI": "ari:cloud:jira-servicedesk::site/be8a4606-6804-4215-b486-6b0057e1fa6f"
}
},
"writeAccessType": "UNRESTRICTED",
"collaborators": [],
"billingType": "NORMAL",
"idUuid": "0191472a-f488-7876-8a9a-78ce5e1dd9a2"
}
]
}
This automation rule is intended to add multiple users to specific groups in Jira using webhook integrations. Here's an overview of how the rule works:
1. Trigger: The rule is triggered manually by an issue action in Jira (manual trigger on an issue). This allows users to initiate the rule when needed.
2. Conditions:
* The first condition checks if a custom field (customfield_10104) in the issue is not empty. Here customfield_10104 represents the field where the user details are added in jira issue.
* The second condition checks if another custom field (customfield_10108) is not empty. Here customfield_10108 represents the field where the user details are added in jira issue.
3. Actions:
* Log actions are used throughout the rule to provide debug information, logging various values like the user or group.
* The main action involves branching based on the value of customfield_10108. This value is transformed (replacing spaces with +), and a branch is created to process the group name stored in the field.
4. Webhooks:
* A webhook is called to retrieve the group ID from Jira's REST API based on the group name.
* Another webhook is used to pass user information (from customfield_10104) and the group ID obtained from the earlier webhook to a different service. This service likely handles adding users to the appropriate groups.
5. Custom Variables:
* The rule creates custom smart variables (groupidlist and accid) to store the group IDs and account IDs of the users. These are later used in the webhook payloads.
6. Final Webhooks:
* The rule sends POST requests to external endpoints https://automation.atlassian.com with the issue key, user account IDs, and group IDs in a custom JSON format. These endpoints likely process the addition of users to the groups.
NOTE:
Make sure to replace customfield_10104 and customfield_10108 once the rule is imported to your instance.
This rule is also designed with logging at several stages to help troubleshoot or track its execution flow. The rule interacts with Jira's APIs and external systems through webhooks, making it capable of automating user management tasks based on custom issue data.
Rule 2: Add users to group
1. Trigger, here we use a Incoming webhook trigger , this incoming web hook doesn’t need authentication headers
2. Branch (jira.smart.values.branch):
* Type: SMART value-based branch.
* It uses the value {{webhookData.issue.user.accountid}} to perform actions for each user account ID involved.
* Inside the Branch:
* Action 1 (codebarrel.action.log): Logs the accountid for tracking.
* Action 2 (jira.issue.outgoing.webhook): Sends a POST request to an external service:
* URL: Sends a request to https://atl-test-rhameed2.atlassian.net/rest/api/3/group/user?groupId={{webhookData.issue.group}} to potentially add the user to a group.
* Headers: Includes an Authorization header with an encoded string (likely a basic authentication token).
* Body: The request sends a JSON payload with the user’s account ID: { "accountId": "{{accountid}}" }.
* Error Handling: The rule is configured to continue execution even if there is an error (continueOnErrorEnabled: true).
By combining these two rules, you can successfully complete adding multiple user to multiple groups in a Jira issue.