---
title: "Integration with Automation for Jira"
canonical: "https://docs.getxray.app/space/XRAY/301695466/Integration%20with%20Automation%20for%20Jira"
format: markdown
---
> Macro (toc)


# Overview

The [Automation for Jira](https://marketplace.atlassian.com/apps/1215460/automation-for-jira?hosting=server&tab=overview) app/feature enables users to easily extend and implement automation in Jira without having to code.

This way, users can implement rules that are triggered upon some event, executed if certain condition(s) are met and that perform certain action(s). 

Rules can also be triggered manually or may be scheduled.


> ℹ️ **Please note**
> ℹ️ 
> ℹ️ Automation for Jira has become part of Jira Datacenter offering, enabling automation of flows for all Jira users. Please check Atlassian's [Jira Automation documentation](https://confluence.atlassian.com/automation/) for more info.


Since Xray uses issue types for most of its entities and since Xray provides many JQL functions that allow you to obtain testing-related information, Automation for Jira can be used with Xray in a very straightforward way.


Automation rules are available and, can be created, from the project settings, namely from the "Automation" tab.

![image](media://c4d0996b-e2a0-4b6b-99ee-d9d546ba6dde)


> ℹ️ **Please note**
> ℹ️ 
> ℹ️ The following examples are provided as-is, no warranties attached; use them carefully.
> ℹ️ 
> ℹ️ Please feel free to adapt them to your needs. 
> ℹ️ 
> ℹ️ Note: We don't provide support for Automaton for Jira; if you have doubts concerning its usage, please contact [Automation for Jira's support](https://marketplace.atlassian.com/apps/1215460/automation-for-jira?hosting=server&tab=support).


# Concepts

Jira Automation allows project administrators to implement rules that can make certain processes automated, guaranteeing efficiency and consistency.

The main concepts of Jira Automation follow a very simple approach for defining an automation **rule**: if a certain "thing" happens (**trigger**) and certain **conditions** are met, then execute one or more **actions**.

- **Trigger**: Triggers start the execution of a rule. Triggers can listen for events or be scheduled to run.
  - manual
  - upon field or workflow status changes
  - upon releasing
  - periodic
  - ...
- **Condition**: Actions will only execute if all conditions preceding them pass.
  - "If" statement
  - Issue fields condition
  - ...
- **Action**: Actions perform changes to a system.
  - change fields on issues
  - transition issues
  - web request
  - log
  - ...


It's also possible to run actions on issues that are **related** to the issue that triggered the rule, using "**branches**".


> ℹ️ **Please note**
> ℹ️ 
> ℹ️ Automation rules run asynchronously.  Some actions can run in parallel but usually they're sequential. There is no interaction with the user (except if the trigger was set off manually from Jira's UI).


# Usage Examples

## Jenkins

### Trigger a Jenkins project build from an issue

<span style="color: #000000">In this very simple scenario, we'll implement a rule, triggered manually, that will trigger a Jenkins project/job. The action will be available from within the "More" menu, in all issues of the selected project.</span>

<span style="color: #000000">We're assuming that:</span>

- <span style="color: #000000">you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it</span>
- what the CI job will do, including if it will report the results back to Xray or not, is not relevant


#### Jenkins configuration

In Jenkins, we need to generate an API token for some user, which can be done from the profile settings page.

![image](media://83ed66cf-0ac9-49bb-b654-98fe3a34fb03)

At the project level, we need to enable remote build triggers, so we can obtain an "authentication token" to be used in the HTTP request afterwards.

![image](media://741d8061-42e0-4264-9ad0-21507d83f35b)

The project itself is a normal one, without parameters.

![image](media://90250cda-c956-4c17-9285-959da9dc95c6)


#### Automation for Jira configuration

1. create a new rule and define the "When" (i.e. when it to should be triggered ), to be "Manually triggered"

![image](media://bab1782c-102d-4f6e-a27c-8df4f1bbc431)

2. define an action (i.e. the "Then") as "Send webhook" and configure it as follows

![image](media://c0fe5dc4-9d48-482f-b71b-ee56f1812fff)

- the Webhook URL provided above follows this syntax:
  - <jenkins_base_url>/job/<name_of_jenkins_project_job>/build?token=<token>
- besides the "Content-Type" header that should be "application/json", define also an "Authorization" header having the value "Basic <auth>", where  the base64 encoded <auth> can be [generated](https://www.blitter.se/utils/basic-authentication-header-generator/) using your Jenkins API credentials

After publishing the rule, you can go to the screen of an issue and trigger the Jenkins project/job.

![image](media://b8358f91-a997-485e-8a53-a9cdf5bb13e9)


### Trigger a Jenkins project build from a Test Plan and report the results back to it

<span style="color: #000000">In this simple scenario, we'll implement a rule, triggered manually, that will trigger a Jenkins project/job. The action will be available from within the "More" menu, for all Test Plan issues of the selected project.</span>

<span style="color: #000000">We're assuming that:</span>

- <span style="color: #000000">you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it</span>
- <span style="color: #172b4d">the results will be submitted back to Xray, if the project is configured to do so in Jenkins</span>


#### Jenkins configuration

In Jenkins, we need to generate an API token for some user, which can be done from the profile settings page.

![image](media://83ed66cf-0ac9-49bb-b654-98fe3a34fb03)

At the project level, we need to enable remote build triggers, so we can obtain an "authentication token" to be used in the HTTP request afterwards.

![image](media://741d8061-42e0-4264-9ad0-21507d83f35b)

The project itself is a normal one; the only thing relevant to mention is that this project is a parameterized one, so it receives TESTPLAN, that in our case will be coming from Jira.

![image](media://bf4445fd-4127-4626-b15f-5cbf8ff3d162)


#### Automation for Jira configuration

1. create a new rule and define the "When" (i.e. when it to should be triggered ), to be "Manually triggered"

![image](media://100825b8-2165-42cc-9263-1cee94af7de0)

2. define the condition so that this rule can only be executed from Test Plan issue

![image](media://46753980-e543-4a82-95d2-a40e7f757489)

3. define an action (i.e. the "Then") as "Send webhook" and configure it as follows

![image](media://09b072ad-3a6e-4dc5-a215-08681ad5db75)

- the Webhook URL provided above follows this syntax:
  - <jenkins_base_url>/job/<name_of_jenkins_project_job>/buildWithParameters?token=<token>&TESTPLAN={{issue.key}}
- besides the "Content-Type" header that should be "application/json", define also an "Authorization" header having the value "Basic <auth>", where  the base64 encoded <auth> can be [generated](https://www.blitter.se/utils/basic-authentication-header-generator/) using your Jenkins API credentials


After publishing the rule, you can go to the screen of an issue and trigger the Jenkins project/job.

![image](media://23e3fc81-0233-4c35-90aa-1488e7969727)

## Azure DevOps

### Trigger a Azure DevOps pipeline from a Test Plan and report the results back to it

#### Azure DevOps configuration

<span style="color: #172b4d">We need to create a service connection, using the "incoming webhook" template, so that we can use Azure DevOps API later on.</span>

![image](media://a01c0195-472a-4fe5-ab2a-b2e30b7413ea)


<span style="color: #172b4d">Create a </span>[<span style="color: #172b4d">Personal Access Token (PAT)</span>](https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=preview-page)<span style="color: #172b4d">, so you can use it as the password in API requests, along with the "organization name" as username.</span>

> Macro (inline-media-image)

> Macro (inline-media-image)





<span style="color: #172b4d">Then, in your Azure DevOps repository containing the project's code and tests, create a pipeline </span>`/azure-pipelines.yml`; this pipeline will be triggered using Azure DevOps API.


In the following example, the pipeline will receive the Test Plan issue key as an input parameter. It will then run the build, including the automated tests, and in the end it will report the results back to Xray using "curl" utility.

We need to define a `resources` section, that contains a reference to the webhook configured earlier.


##### **/azure-pipelines.yml**

```yml
parameters:
- name: "testplan"
  type: string
  default: ""

trigger:
- main

resources:
  webhooks:
    - webhook: "MyWebhookTrigger"             ### Webhook alias
      connection: "MyWebhookConnection"       ### Incoming webhook service connection

pool:
  vmImage: ubuntu-latest

steps:

- bash: |
    echo ${{ parameters.testplan }}
  displayName: '(debug) print testplan parameter'

- script: dotnet restore
  displayName: 'install build dependencies'

- script: |
    dotnet test -s nunit.runsettings
  displayName: 'Run tests'
- bash: |
    set -x
    curl -o - -H "Content-Type: multipart/form-data" -u '$(jira_user):$(jira_password)' -F "file=@./bin/Debug/net5.0/TestResults/nunit_webdriver_tests.xml" "$(jira_server_url)/rest/raven/2.0/import/execution/nunit?projectKey=$(project_key)&testPlanKey=${TESTPLAN}"
  displayName: 'Import results to Xray server'

```


Xray endpoint's base URL and the API key credentials (i.e. client id + client secret) are defined in Azure DevOps as variables. These may be marked as secret.

![image](media://f54395b3-d285-4a57-9bb8-0b05c1d09634)

![image](media://77931305-3d91-4cfc-ac73-47b487659a22)


#### Automation for Jira configuration

1. create a new rule and define the "When" (i.e. when it to should be triggered ), to be "Manually triggered"

![image](media://d897c3f1-a7ac-402d-afb2-aece4ef3cfd1)

2. define the condition so that this rule can only be executed from Test Plan issue

![image](media://2a845458-23d6-4a7d-b6a9-15e9e1c3abe6)

3. define an action (i.e. the "Then") as "Send web request" and configure it as follows

![image](media://4ff1afaa-afe4-4c66-ada0-af837f975ed0)


- the web request URL provided above is from [Azure DevOps API, for queueing builds](http://Azure DevOps API, for queueing builds), and follows this syntax:
  - [https://dev.azure.com/<organization_name>/<project>/_apis/build/builds?ignoreWarnings=true&api-version=6.0](#)
- authentication is done using the organization name plus the personal access token, created earlier in Azure DevOps, as the login:password pair used to calculate the Base64 content of the Authorization header
- the "Content-Type" header should be "application/json"
- the HTTP POST body content, defined in the "Custom data" field, will be used to identify the [build definition](https://docs.microsoft.com/en-us/rest/api/azure/devops/build/definitions?view=azure-devops-rest-4.1&viewFallbackFrom=azure-devops-rest-6.0) and also the original Test Plan issue key;
  **custom data (i.e. HTTP body content)**


After publishing the rule, you can go to the screen of an issue and trigger a pipeline run in Azure DevOps.

![image](media://ac93276b-b97d-4a7d-ab5a-8d2bf4bfac17)


![image](media://d768c1db-fecf-495e-a0a1-b966b06750e5)


In this case, since the pipeline was configured to report results back to Xray, a new Test Execution would be created and linked back to the source Test Plan where the automation was triggered from.

![image](media://d74bdbec-dc06-4ef7-b015-b2ee0ce6d3d0)

![image](media://95f6f9a7-06af-4ef3-8212-c077a0930413)


## Travis CI

### Trigger a TravisCI project build from a Test Plan and report the results back to it

<span style="color: #003366">In this simple scenario, we'll implement a rule, triggered manually, that will trigger a TravisCI project/job. The action will be available from the "Automation" panel, for all Test Plan issues of the selected project.</span>

<span style="color: #003366">We're assuming that:</span>

- <span style="color: #003366">you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it</span>
- <span style="color: #003366">the results will be submitted back to Xray, if the project is configured to do so in TravisCI</span>


#### TravisCI configuration

<span style="color: #003366">In TravisCI, we need to generate an API authentication token for some user, which can be done from the My Account settings page.</span>

![image](media://eba5c9b1-efdc-4025-92bc-f33fc16b843f)

<span style="color: #003366">Once we have the authentication token we followed the </span>[<span style="color: #003366">TravisCI API documentation</span>](https://docs.travis-ci.com/user/triggering-builds/)<span style="color: #003366"> to configure the following steps on the Jira side. </span>

<span style="color: #003366">For the Travis CI the important change we must do is in the YAML file that will configure Travis CI pipeline, we use the following configuration to achieve that:</span>

##### **.travis.yml**

```yml
sudo: false
language: java
jdk:
  - openjdk8
cache:
  directories:
  - "$HOME/.cache"
  
jobs:
  include:
    - stage: test and report to Xray
      script:
        - |
            echo "building repo..."
            mvn clean compile test --file pom.xml
            curl -H "Content-Type: multipart/form-data" -X POST -u $USERNAME:$PASSWORD -F "file=@target/surefire-reports/TEST-com.xpand.java.CalcTest.xml" "https://$JIRASERVER/rest/raven/2.0/import/execution/junit?projectKey=$PROJECTKEY&testPlanKey=$TESTPLAN"
            echo "done"
```


<span style="color: #003366">For more details about this configuration please check the </span>[<span style="color: #003366">TravisCI tutorial documentation</span>](https://docs.travis-ci.com/user/tutorial/)<span style="color: #003366">.</span>

<span style="color: #003366">As you can see we are pushing results back to Xray with the last curl command:</span>

##### **curl command**

```yml
curl -H "Content-Type: multipart/form-data" -X POST -u $USERNAME:$PASSWORD -F "file=@target/surefire-reports/TEST-com.xpand.java.CalcTest.xml" "https://$JIRASERVER/rest/raven/2.0/import/execution/junit?projectKey=$PROJECTKEY&testPlanKey=$TESTPLAN"
```


<span style="color: #003366">On this command we are passing the project key in order to report back to a specific Project on the Xray side. Further ahead we will show how it is populated.</span>

- *<span style="color: #003366">PROJECTKEY</span>*<span style="color: #003366"> - The key that identifies the project on the Jira side.</span>
- *<span style="color: #003366">TESTPLAN</span>*<span style="color: #003366"> - The Test Plan key used to identify the Test Plan to associate the execution with.</span>

<span style="color: #003366">Once we have the authentication token, we follow the </span>[<span style="color: #003366">TravisCI API documentation</span>](https://docs.travis-ci.com/user/triggering-builds/)<span style="color: #003366"> to configure the following steps on the Jira side. </span>

#### <span style="color: #003366">Automation configuration</span>

<span style="color: #003366">On the Jira side we will use the Automation capabilities that it provides out of the box, so within the administration area go to the automation entry in the system settings and: </span>

1. <span style="color: #003366">create a new rule and define the "When" (i.e. when it to should be triggered), to be "Manually triggered"</span>

![image](media://ec92012e-085a-44bf-ae13-b7d1e1802179)

2.<span style="color: #003366">Define a condition, in our case we  will define that only Test Plan issue types will be allowed to trigger this pipeline, this is achieved with the following condition:</span>

![image](media://19dc7582-c001-450e-88b9-da8f9d6637a9)


3. *define an action (i.e. the "Then") as "Send webhook" and configure it as follows*

![image](media://9c56a4f5-d38c-41a0-b48a-a5538562e132)


- <span style="color: #003366">the Webhook URL provided above follows this syntax:</span>
  - *<span style="color: #003366"><TravisCI_API_URL>/repo/{slug|id}/requests</span>*<span style="color: #003366"> (The </span>*<span style="color: #003366">%2F</span>*<span style="color: #003366"> in the request URL is required so that the owner and repository name in the repository slug are interpreted as a single URL segment.)</span>
- <span style="color: #003366">besides the "</span>*<span style="color: #003366">Content-Type</span>*<span style="color: #003366">" header that should be "</span>*<span style="color: #003366">application/json</span>*<span style="color: #003366">", define also an "</span>*<span style="color: #003366">Authorization</span>*<span style="color: #003366">" header having the value "t</span>*<span style="color: #003366">oken <token></span>*<span style="color: #003366">", where  you will place the authentication token obtained previously in the TravisCI page and the "</span>*<span style="color: #003366">Travis-API-Version</span>*<span style="color: #003366">" header is also mandatory and it will contain the version used.</span>
- <span style="color: #003366">Custom data</span>
  - <span style="color: #003366">We included the simplest possible just to trigger the pipeline from the master branch.</span>
  - <span style="color: #003366">Added environment configuration variables to be used later in the TravisCI pipeline</span>
    - *<span style="color: #003366">TESTPLAN</span>*<span style="color: #003366"> - that will be automatically filled with the test plan key from where the pipeline is triggered.</span>
    - *<span style="color: #003366">PROJECTKEY</span>*<span style="color: #003366"> - that will be automatically filled in with the project key.</span>

<span style="color: #003366">After publishing the rule, you can go to the screen of an issue and trigger the TravisCI project/job.</span>

![image](media://7e7092ee-5f25-47d3-adec-6da949987a39)


In this case, since TravicCI was configured to report results back to Xray, a new Test Execution would be created in Jira/Xray.

![image](media://a9064791-6e65-40ac-a8dd-5252f8f89f6f)

Associated with the Test Plan that we have passed along:

![image](media://d60819ef-b6cb-456d-a6d9-dad06c72dece)


## Generic automation of processes

### <span style="color: #172b4d">Copy fields from requirement/Story to Test whenever creating a Test or linking it to a story</span>

<span style="color: #172b4d">Sometimes it may be useful to copy some fields from the requirement/Story to the Tests that cover it.</span>


#### <span style="color: #003366">Automation configuration</span>

<span style="color: #000000">On the Jira side we will use the Automation capabilities that it provides out of the box, so within the administration area go to the automation entry in the system settings and: </span>

1. <span style="color: #000000">create a new rule and define the "When" (i.e. when it should be triggered) to be "Issue linked". Since Xray, by default, uses the issue link type "Tests" to establish the coverage relation between a Test and the requirement, we can take advantage of that to trigger the rule whenever such issue link is created.</span>
2. <span style="color: #000000">create a condition to ensure that the rule only runs for Test issues</span>
3. <span style="color: #000000">use an "Edit issue" action to set the fields on the Test based on the fields of the linked requirement/Story (i.e., the </span>*<span style="color: #000000">destination</span>*<span style="color: #000000"> issue of the linking event). In this example, we'll copy the values of Urgency and Probability custom fields.  </span>


<span style="color: #172b4d">This rule will run:</span>

- <span style="color: #172b4d">whenever a Test is created from the requirement/Story issue screen</span>
- <span style="color: #172b4d">whenever a Test has been initially created and later on linked to the requirement</span>

### Reopen/transitionTests linked to a requirement whenever the requirement is transitioned or changed

Whenever you change the specification of a requirement/story, you most probably will need to review the Tests that you have already specified.

The following rule tries to perform a transition of **all** Tests linked to a requirement.

#### <span style="color: #003366">Automation configuration</span>

<span style="color: #003366">On the Jira side we will use the Automation capabilities that it provides out of the box, so within the administration area go to the automation entry in the system settings and: </span>

1. <span style="color: #000000">create a new rule and define the "When" (i.e. when it should be triggered) to be "Field value changed"</span>
  2. <span style="color: #000000">Note: we could also define the trigger to be based on the transition of the requirement issue to a certain workflow status; in that case we would define it, for example, as shown below.</span>
2. <span style="color: #000000">create a condition to ensure that the rule only runs for Story and Epic issues; adjust these to include all the "requirement" issue types (i.e., the ones that you can cover with Tests)</span>
3. <span style="color: #000000">create a "branch rule / related issues" to obtain related Tests using JQL and the </span>`requirementTests()`<span style="color: #000000"> JQL function and run one, or more, action(s) on them</span>
4. <span style="color: #000000">under the "For JQL" block, create a action "Transition the issue to" in order to reopen the related Test issues</span>

# References

- [Automation for Jira in the Atlassian Marketplace](https://marketplace.atlassian.com/apps/1215460/automation-for-jira?hosting=server&tab=overview)
- [Jira Automation in Jira DC](https://confluence.atlassian.com/automation/)
  - [Jira smart values - issues](https://confluence.atlassian.com/automation/jira-smart-values-issues-993924860.html)
  - [Jira smart values - lists](https://confluence.atlassian.com/automation/jira-smart-values-lists-993924868.html)
  - [Jira smart values - text fields](https://confluence.atlassian.com/automation/jira-smart-values-text-fields-993924863.html)
  - [Jira smart values - users](https://confluence.atlassian.com/automation/jira-smart-values-users-993924862.html)
  - [Jira smart values - conditional logic](https://confluence.atlassian.com/automation/jira-smart-values-conditional-logic-1081351607.html)
  - [Jira smart values - JSON functions](https://confluence.atlassian.com/automation/jira-smart-values-json-functions-993924865.html)
  - [Branch automation rules to perform actions on related issues](https://confluence.atlassian.com/automation/branch-automation-rules-to-perform-actions-on-related-issues-993924648.html)