---
title: "Trigger a TravisCI project build"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/44565631/Trigger%20a%20TravisCI%20project%20build"
format: markdown
---
> Macro (toc)

# Trigger a TravisCI project build from an issue

<span style="color: #003366">In this very 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, in all 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">what the CI job will do, including if it will report the results back to Xray or not, is not relevant</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://97304329-8b72-42bf-8a4a-b64a5bca2267)

<span style="color: #003366">We have defined the following configuration in our source code that will be used in TravisCI configuration of the pipeline:</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
            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"
            echo "done"


```

<span style="color: #003366">For the configuration of the YAML file we used 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: 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"
```

<span style="color: #003366">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.</span>

- <span style="color: #003366">PROJECTKEY - The key that identifies the project on the Jira side.</span>

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

## Automation configuration

On the Jira side we will use the Automation capabilities that it provides out of the box, so within the project you want to use automation go to project settings and: 

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

![image](media://ad05cdbc-cc4c-4a53-b009-b3352e454504)

2. <span style="color: #003366">define an action (i.e. the "Then") as "Send web request" and configure it as follows</span>

![image](media://abe17ed5-0d3f-4d92-9376-5af7ca92ef2c)


- <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 %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.)</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 "</span>*<span style="color: #003366">token <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 </span><span style="color: #003366">and it will contain the version used</span><span style="color: #003366">.</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">After publishing the rule, you can go to the screen of an issue and trigger the TravisCI project/job.</span>

![image](media://7fcb4761-3817-4bb5-b6a8-8e7bd97cf3bb)


<span style="color: #003366">In this case, since TravisCI was configured to report results back to Xray, a new Test Execution would be created in Jira/Xray.</span>

![image](media://e4faca38-d154-4c0c-aaba-5b3252f11d42)


# 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://97304329-8b72-42bf-8a4a-b64a5bca2267)

<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 TravisCI the important change we must do is in the YAML file that will configure TravisCI 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
            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"


```

<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: 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"
```

<span style="color: #003366">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.</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 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">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 project you want to use automation go to the automation entry in the project 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://896bc109-370b-4292-bb17-f0f8508249f6)

2. d<span style="color: #003366">efine a condition, in our case we will define that only Test Plan issue types will be allowed to trigger this pipeline; this could also be defined on the previous step</span>

![image](media://f4ca0132-6372-4c2f-9550-314f6dc0aa4e)


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

![image](media://df1bda8d-0b68-4f46-89df-2a9159f07225)


- <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 a Test Plan issue and trigger the TravisCI project/job.</span>

![image](media://5931b7ef-4744-4375-9d85-3a27736f956d)


In this case, since <span style="color: #003366">TravisCI</span> was configured to report results back to Xray, a new Test Execution would be created in Jira/Xray.

![image](media://e4faca38-d154-4c0c-aaba-5b3252f11d42)

Associated with the Test Plan that we have passed along:

![image](media://66a22d8c-da16-453a-ab56-a846a910dacc)

# References

- [GraphQL to JSON Body Converter](https://datafetcher.com/graphql-json-body-converter)
- [Jira Automation in Jira Cloud](https://support.atlassian.com/cloud-automation/docs/jira-cloud-automation/)
  - [Jira smart values - issues](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/)
  - [Jira smart values - lists](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/)
  - [Jira smart values - text fields](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/)
  - [Jira smart values - users](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-users/)
  - [Jira smart values - conditional logic](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/)
  - [Jira smart values - JSON functions](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/)

> Macro (__confluenceADFMigrationUnsupportedContentInternalExtension__)