Automation For Jira - How to validate "Assignable user" permission when cloning issues
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
要約
When working with complex automation rules that are cloning issues in another target project, using an existing assignee as an input value often comes as a challenge because the value is controlled by the end user, and the current assignee in the source project does not necessarily have "Assignable user" permission in the target project. In cases like those, the permission validation will fail, and the new issue will not be created, and the rule will fail to complete. To overcome this situation, we need to first validate the appropriate permissions before action.
環境
- Jira Data Center Only (not applicable to Server licenses)
- Applicable Jira / A4J (Automation for Jira) versions which include the Create Variable action:
- Jira 9.11.0 and any higher version (this Jira version ships with A4J 9.0.1)
- OR Jira 8.20.0 and any higher version, in combination with A4J 9.0.1 or any higher version
診断
The lack of "Assignable User" permission problem can be identified in the audit logs of the automation rule. There is always an "Error creating issue" entry with following content "User 'username' cannot be assigned issues. (assignee)".
ソリューション
To achieve our new requirements, we will utilize a Send Web Request action, call Jira REST API, and validate whether the user we intend to use has "Assignable User" permission in the target project.
Once we have the webhook response, we will parse the body for results. If the response is an empty collection, that means that the validated user has no appropriate "Assignable User" permission in the target project. With this, we will use conditional logic on the Assignee field in the Clone Issue action.
ルール構成
Here is a very simplified rule that can be used as an example. The rule will need to be configured as follows:
- Add the Manual trigger. Optionally, restrict the trigger based on the group.
- Add the action Create Variable. The purpose of this variable is to hold the user that needs to be checked. The value of this variable can come from {{issue.assignee}} or {{issue.customfield_XXXXX}}, depending on your exact requirements. In this example, we will attempt to clone the issue and set the assignee to the value of a user picker (single user) custom field which can be accessed via the smart value customfield_XXXXX, where XXXXX is the Custom Field ID which can be found as per How to find a Custom Field ID.
- Variable Name: issueAssigne
Smart value:
{{issue.customfield_XXXXX}}
- Add the action Send Web Request with the following configuration:
- Webhook URL: JIRA_BASE_URL/rest/api/2/user/assignable/search?username={{issueAssigne}}&project=PKEY
- Replace JIRA_BASE_URL with the base URL of your Jira instance.
- Replace PKEY with the target project key.
Headers:
Authorization header with Bearer token. For on details how to create a PAT token please refer to the following article: Using Personal Access Tokens.
- HTTP Method: GET
- Webhok Body: Empty
- Wait for Response: Checked
- Webhook URL: JIRA_BASE_URL/rest/api/2/user/assignable/search?username={{issueAssigne}}&project=PKEY
- Add Clone Issue action with the following configuration:
Project: Chose a target project.
- Issue Type: Chose appropriate Issue Type.
- Chose fields to set: Assignee
Assingee: Set Value
The following options set the assignee of the cloned issue to the user stored in the smart value issueAssigne if the previous web request returns the user in the body (which means that the user has the assignable permission) or leave it unassigned by passing an empty string.
{{if(webhookResponse.body.size.gt(0), issueAssigne, "")}}
To assign the issue to a specific user in case the issueAssigne doesn't have the required permission, you can add the username of the designated user like this.
{{if(webhookResponse.body.size.gt(0), issueAssigne, "admin")}}
Screenshot showing the rule
Create Variable Action:
Send Web Request Action:
Clone Issue Action:
Jira Data Center - Rest API
For additional information and to get started with Jira Data Center Rest API, read the reference documentation: Jira Server platform REST API] and Atlassian Developer - Rest API.
The Jira Software and Jira Service Management applications have REST APIs for their application-specific features, like sprints (Jira Software) or customer requests (Jira Service Management).