# Jenkins

Testery integrates with Jenkins via the [Testery CLI](/integrations/testery-cli-docs.md) or [Testery REST API](/integrations/testery-rest-api.md). 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**](/integrations/testery-cli-docs.md) **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**](/get-to-know-testery/deployments.md)**.**

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.

![](/files/-MVXIye7qAFRjoBENSdZ)

**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;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.testery.io/integrations/ci-cd-integration-guide/jenkins.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
