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

# 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 the "Automation" panel, 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://6d0f14d0-c738-4345-9829-6e83d42d6e76)

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://ca21f9ce-ba34-4d0f-b966-2976aef29f51)

The project itself is a normal one, without parameters.

![image](media://b4973cbf-ce7e-4bd4-a2ae-c16c28051bd2)


## Automation configuration

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

![image](media://c39c6b9e-e5e9-4081-a76c-f118c3992c6d)

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

![image](media://a226973e-2414-4ee7-81b2-4452a5bbf274)

- 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://08d395b1-3920-4d22-84b8-90b0d6d0bbd3)


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

![image](media://0f2cf6c6-eb57-461e-b016-6b596d9e5ad3)

# 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 the "Automation" panel, 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://6d0f14d0-c738-4345-9829-6e83d42d6e76)

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://2777a896-53d3-444e-9088-9c2e2c2f0223)

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

![image](media://2ff9b045-4422-40cc-8f4a-bc13e1088707)


## Automation configuration

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

![image](media://ffb1e239-35e3-4501-834f-747053fcfbbf)


2. define the condition so that this rule can only be executed from Test Plan issue; this can be done on the manual trigger directly or  we can also define an explicit condition for it

![image](media://6f798155-7cc7-4161-9b7c-6abc69d43d5a)

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

![image](media://b0c5a983-f591-420b-9037-81a0f9415525)

- 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://b68fb6a9-f7cb-4f2c-a18d-92b7a3548050)


In this case, since Jenkins 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://aa704b28-ad5d-4595-98f5-2825a1a6916f)

![image](media://186fa666-11e4-4355-820c-4a8b53a7f9dd)


# 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/)