# Jenkins

> Upload JUnit test results from a Jenkins build to an Arcus test run so test case statuses update automatically.

Integrating Jenkins with Arcus by Testsigma uploads your JUnit test results to a test run at the end of a build, so test case statuses update automatically.

## Prerequisites

- A Jenkins account.
- A project in Arcus by Testsigma with at least one [test run](https://testsigma.com/docs/arcus/v2/run-tests/test-runs/).
- An Arcus by Testsigma [API token](https://testsigma.com/docs/arcus/v2/settings/api-keys/).

## Store the API token in Jenkins

1. On the Jenkins dashboard, click **Manage Jenkins**.

2. Under **Security**, click **Credentials**.

3. Under **Stores scoped to Jenkins**, click **(global)** in the **Domain** column.

4. On the **Global credentials** page, click **Add Credentials**.

5. In the **Kind** dropdown, select **Secret text**.

6. In **Secret**, enter your Arcus by Testsigma API token.

7. In **ID**, enter `TESTSIGMA_API_TOKEN`.

8. Click **Create**.

## Configure the pipeline

1. On the Jenkins dashboard, click **New Item**.

2. In **Enter an item name**, enter a name for the pipeline.

3. Select **Pipeline**, then click **OK**.

4. On the **Configuration** page, scroll to the **Pipeline** section.

5. In the **Definition** list, select **Pipeline script**.

6. In **Script**, paste the script that follows, replacing its 2 placeholders.

```groovy
pipeline {
    agent any
    environment {
        TESTSIGMA_API_TOKEN = credentials('TESTSIGMA_API_TOKEN')
    }
    stages {
        stage('Run Tests') {
            steps {
                // Run your own test script here
                sh './run-tests.sh'
            }
        }
        stage('Upload to Testsigma TMS') {
            steps {
                // The test result file must exist at the path given below
                sh '''
                curl --location 'https://arcus.testsigma.com/api/v1/projects/<Project_ID>/junit-import/test-run/<Run_ID>' \
                --header "Authorization: Bearer $TESTSIGMA_API_TOKEN" \
                --form "junit_xml=@target/test-results/test-report.xml"
                '''
            }
        }
    }
}
```

- Replace `` with your project ID, which you can retrieve using the Arcus by Testsigma APIs.
- Replace `` with the run ID, which appears in the URL when you view a test run: `https://test-management.testsigma.com/ui/test_runs//`.
- Point `junit_xml` at the path your build writes its JUnit XML report to.

Then click **Apply**, and click **Save**.

## Trigger a build

1. On the Jenkins dashboard, click the configured pipeline.

2. In the Jenkins sidebar, click **Build Now**.

When the build succeeds, the test case statuses in the associated test run update automatically.
