# Jenkins

Testery integrates with Jenkins via the [Testery CLI](https://docs.testery.io/integrations/testery-cli-docs) or [Testery REST API](https://docs.testery.io/integrations/testery-rest-api). We strongly recommend using the CLI as it is usually faster to get running and provides better integration functionality. The CLI requires Python 3.6 or greater.

**Step 1. Retrieve your Testery API Token.** To retrieve your token, click **Settings → Integrations → Show API Token** and copy the token that is displayed. Keep this token secure as it allows access to Testery on your behalf. If you don't already have a Testery account, you can sign up for a free account in a few minutes [here](https://testery.io/signup).

**Step 2. Store your Testery API Token in Jenkins as a secret.** For more information on the various options for doing this, see <https://www.jenkins.io/doc/book/using/using-credentials/>

You can now access this token as follows in your `Jenkinsfile`:&#x20;

```groovy
pipeline {
    // ...
    environment {
        TESTERY_API_TOKEN = credentials('testery-api-token')
    }
    // ...
}
```

**Step 3.** **Add steps to your Jenkins pipeline to install the** [**Testery CLI**](https://docs.testery.io/integrations/testery-cli-docs) **and tell Testery when there are deployments ready to be tested.**

Here is a sample `Jenkinsfile`:

```groovy
pipeline {
    agent any

    stages {
        // ...
        stage('Testery Tests') {
            steps {
                script {
                    echo "Running E2E tests..."
                    def commit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
                    sh 'pip install testery --upgrade'
                    sh 'testery create-deploy --token ${TESTERY_API_TOKEN} --project <yourTesteryProjectKey> --environment <yourTesteryEnvironmentKy> --build-id ${BUILD_ID} --commit ${commit}' 
                }
            }
        }
        // ...
    }
}
```

**Step 4. Configure Testery to trigger a test run whenever there are** [**deployments**](https://docs.testery.io/get-to-know-testery/deployments)**.**

Go to **Schedules**, click **Add New Schedule** and then specify that you want the tests to **Run on Deploy**. The Run on Deploy option will only be available after you have completed the previous steps.

![](https://4041872331-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MK0kYmwONk3GqQ8OhVA%2Fuploads%2Fgit-blob-d4374bfe1418c09b23f50388c7f5e7747af254d8%2Fimage.png?alt=media)

**Step 5. You're all set!**

Tests will now run whenever your Jenkins pipeline is run. If you get stuck and would like any assistance, please don't hesitate to reach out to <support@testery.io>.&#x20;
