Configuring Jira Automation to add issues to tree

Overview

A problem arises when users create issues outside of the R4J project tree. Such issues are not visible in the tree and tend to be overlooked. R4J does not yet provide a built-in feature to solve this problem, but in this page we explain how to create Jira Automation rules to recognize such issues and automatically add them to a specific place in a project tree, for example, in a folder dedicated to new issues.

Jira Authentication

The automation solution uses a REST API web request relying on basic authentication. The required base64 encoded authentication string must be defined in advance for a specific user account. While a real user account can be used for this purpose (e.g. the account of a project admin or the Jira system admin), we recommend that a separate, dedicated account be created, due to the fact that Jira does not limit the visibility of the user’s authentication string in automation rules, thus allowing for the possibility of misuse. The dedicated account should be:

  • Enabled only for specific projects.

  • Restricted by the R4J tree permission so that it can only update the R4J tree structure.

To create the necessary authentication string, the instructions provided by Atlassian should be followed. See the second option at REST API Authentication and Supply basic auth headers.

Creating the Automation Rule

To configure an automation rule, you need to be a Global or Project administrator.

  • For a global rule, go to Jira Settings > System > Global Automation.

  • For a project-specific rule, go to Project Settings > Automation.

Follow the steps below to set up an automation rule.

Step

Action

Explanation

Step

Action

Explanation

Create a new rule

Select the Create rule button.

 

Create a trigger for the rule

Select the trigger Issue created in section Issue Triggers.

image-20240227-171347.png

 

The rule is triggered when a new issue is created.

Add conditions

Select an if condition, e.g. Issue matches JQL

image-20240228-131350.png

 

Different conditions can be specified to enforce certain behavior. If the rule is created in a specific project, then it is automatically limited to that project. If the rule is global, then the condition should specify the projects for which it is valid unless it is actually intended to apply to all projects.

There is no need to add a condition that the issue is not already in the project tree. When an issue is created in a R4J project tree to begin with, the execution of the rule is triggered, but fails immediately, without changing the location of the issue.

Add variables

Select the action Create variable

 

Specify two smart variables:

  • targetProjectKey: The project key where the new issues should be added.

  • targetFolderKey: The parent folder key where the new issue should be added in the project tree.

Example of how to specify the variable targetProjectKey:

Add REST API web request

Select the action Send web request

 

Web request URL: Use https://eu.r4j-cloud.easesolutions.com/rest/api/1/tree/projects/{{targetProjectKey}}/items, where targetProjectKey is the smart variable of the target project as defined above.

  • Details of the request can be found at R4J Cloud REST API Reference.

  • If the data residency feature is activated for R4J, the URL may be different. Details will follow.

HTTP method: Post

Web request body: Custom data

Custom data value:

{ "id": null, "jiraIssueId": null, "jiraIssueKey": "{{targetFolderKey}}", "items": [ { "jiraIssueId": null, "jiraIssueKey": "{{issue.key}}", "position": 1 } ] }

Note how the following values are set in the data value:

  • jiraIssueKey: The value is the smart variable targetFolderKey defined above.

  • items:

    • issue.key: The value is a variable containing the key of the new issue.

    • position: Use 1 to insert the issue in the first position and 0 to insert it in the last position. To insert an issue between the first and last position, use the number of the desired position - for example, use 3 for the third position. If there are fewer issues than the given number, the issue is inserted in the last position.

Headers: Add the following two key/value pairs:

  • key: X-Atlassian-Base-Url

  • value: Your Jira cloud server URL (e.g. https://mycompany.atlassian.net/)

  • key: Authorization

  • value: your basic authentication hash key, e.g. Basic ZnJlZDpmcmVk - see Jira Authentication.

Example of headers:

Optional: Validate the web request

 

To validate the web request:

  • Replace the smart values {{targetProjectKey}} and {{targetFolderKey}} by existing values, e.g.
    "jiraIssueKey": "ABC-100",

  • Enter an issue key of an issue not yet in the tree.

  • Select Validate.

The returned error code should be 200 for successful execution. For debugging check out the returned payload. Note that the rule is not actually executed.

Enable the rule

Provide a name for the rule and then enable it by selecting Turn it on.