Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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:

  • you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it
  • the results will be submitted back to Xray, if the project is configured to do so in TravisCI


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.

Image Added

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:
.travis.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
            export token=$(curl -H "Content-Type: application/json" -X POST --data "{ \"client_id\": \"$CLIENT_ID\",\"client_secret\": \"$CLIENT_SECRET\" }" https://xray.cloud.xpand-it.com/api/v2/authenticate| tr -d '"')
            echo $token
            curl -H "Content-Type: text/xml" -H "Authorization: Bearer $token" --data @target/surefire-reports/TEST-com.xpand.java.CalcTest.xml  "https://xray.cloud.xpand-it.com/api/v2/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 command

curl -H "Content-Type: text/xml" -H "Authorization: Bearer $token" --data @target/surefire-reports/TEST-com.xpand.java.CalcTest.xml  "https://xray.cloud.xpand-it.com/api/v2/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 in the Xray side, we will further ahead show how it is populated.

  • PROJECTKEY - The key that identifies the project on the Jira side.
  • TESTPLAN - The Test Plan key used to identify the Test Plan to associate the execution with.

Once we have the authentication token we followed 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"

Image Added

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:

Image Added


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

Image Added


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

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

Image Added


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

Image Added

Associated with the Test Plan that we have passed along:

Image Added


References