# CircleCI

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

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

1. Open your project in CircleCI.

2. Go to **Project Settings > Environment Variables**.

3. Add a variable. Enter `TESTSIGMA_API_TOKEN` in **Name** and your Arcus by Testsigma API token in **Value**.

Keep this value secret and out of build logs. Don't echo the token in a step.

## Configure the pipeline

1. In your repository, open or create `.circleci/config.yml`.

2. Add the following, then replace the 2 placeholders as described below.

```yaml
version: 2.1

jobs:
  build:
    docker:
      - image: cimg/openjdk:8.0
    environment:
      TESTSIGMA_API_TOKEN: << pipeline.parameters.testsigma_api_token >>
    steps:
      - checkout

      - run:
          name: Build and test with Maven
          command: mvn clean package

      - run:
          name: Upload JUnit results to Testsigma
          command: |
            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/surefire-reports/TEST-MyTests.xml"

workflows:
  version: 2
  test_and_upload:
    jobs:
      - build:
          parameters:
            testsigma_api_token:
              type: env_var_name
              default: TESTSIGMA_API_TOKEN
```

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

## Trigger a build

Commit and push to the repository connected to CircleCI. CircleCI runs the workflow, and when it finishes the test run in Arcus by Testsigma updates with the execution results.
