Overview

The Automation for Jira 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.


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 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.


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.


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.


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


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

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.

We're assuming that:


Jenkins configuration

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

 

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.

The project itself is a normal one, without parameters.


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"

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

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


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

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.

We're assuming that:


Jenkins configuration

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

 

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.

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.


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"

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

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


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

Azure DevOps

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

Azure DevOps configuration

We need to create a service connection, using the "incoming webhook" template, so that we can use Azure DevOps API later on.


Create a Personal Access Token (PAT), so you can use it as the password in API requests, along with the "organization name" as username.

  



Then, in your Azure DevOps repository containing the project's code and tests, create a pipeline /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.


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.

 


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"

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

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

 



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



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.


Travis CI

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

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.

We're assuming that:


TravisCI configuration

In TravisCI, we need to generate an API authentication token for some user, which can be done from the My Account settings page.

Once we have the authentication token we followed the TravisCI API documentation to configure the following steps on the Jira side. 

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:

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"


For more details about this configuration please check the TravisCI tutorial documentation.

As you can see we are pushing results back to Xray with the last curl command:

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"


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.

Once we have the authentication token, we follow the TravisCI API documentation to configure the following steps on the Jira side. 

Automation configuration

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: 

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


2.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:



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



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



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


Associated with the Test Plan that we have passed along:



Generic automation of processes

Copy fields from requirement/Story to Test whenever creating a Test or linking it to a story

Sometimes it may be useful to copy some fields from the requirement/Story to the Tests that cover it.


Automation configuration

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: 

  1. 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.
  2. create a condition to ensure that the rule only runs for Test issues
  3. use an "Edit issue" action to set the fields on the Test based on the fields of the linked requirement/Story (i.e., the destination issue of the linking event). In this example, we'll copy the values of Urgency and Probability custom fields.  


This rule will run:

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.

Automation configuration

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: 

  1. create a new rule and define the "When" (i.e. when it should be triggered) to be "Field value changed"
    1. 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.
  2. 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)
  3. create a "branch rule / related issues" to obtain related Tests using JQL and the requirementTests() JQL function and run one, or more, action(s) on them
  4. under the "For JQL" block, create a action "Transition the issue to" in order to reopen the related Test issues

References