# CircleCI

> Add a CircleCI job that runs the Testsigma trigger script and gates deployment on the result.

Testsigma offers webhooks any CLI tool can call: a CircleCI job triggers a test plan on each code change and gates deployment on the result.

## Prerequisites

- A CircleCI account connected to your source control (GitHub, Azure, etc.).
- A CI/CD pipeline in CircleCI.

## Get the API key and test plan ID

1. **Create an API key**: in Testsigma, go to **Settings > API Keys** and create a key. It authenticates the trigger requests coming from CircleCI.

2. **Copy the test plan ID**: open the test plan the pipeline should run and copy its ID from the **CI/CD Integrations** tab in the test plan details.

## Add the script to your repository

1. **Copy the script**: take the generic trigger script from the [shell script](https://testsigma.com/docs/v2/integrations/ci-cd/shell-script/) page.

2. **Set your values**: update the API key and test plan ID in the script.

3. **Commit it**: upload the script file to your code repository (GitHub, Bitbucket, Azure, or similar) and commit.

## Configure the pipeline

1. **Pick the project**: in CircleCI, create a new project or select an existing one, then click **Setup Project**.

2. **Add the job**: in `config.yml`, add a job that makes the script executable and runs it. If you start from a CircleCI template, the job belongs in the section that begins with the comment **run tests!**.

   ```yaml title="config.yml"
   # Java Maven CircleCI 2.0 configuration file
   #
   # Check https://circleci.com/docs/2.0/language-java/ for more details
   #
   version: 1.0
   jobs:
    build:
      steps:
        - run: chmod a+x ./trigger_testsigma_tests_and_wait.sh
        - run: ./trigger_testsigma_tests_and_wait.sh
   ```

3. **Start the build**: click **Start Building** at the top right. A dialog states that CircleCI will add the `config.yml` to the selected repository; click **Add Config**. CircleCI takes you to the Pipelines page.

From now on, every change to the repository triggers a build, and the build starts the test plan in Testsigma. The script waits until the run completes and checks that the tests passed.
