> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usetuner.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Other CI tools

> Run Tuner simulations from GitLab CI, CircleCI, Jenkins or any other pipeline with the Tuner CLI, and pass or fail the build on the exit code.

> [!NOTE]
>
> Tuner has a [GitHub Action](https://docs.usetuner.ai/docs/simulation/ci/github-actions). Every other CI tool runs the [Tuner CLI](https://docs.usetuner.ai/docs/simulation/cli.md) directly and passes or fails the build on its exit code. These tools get no pull request comment and no job summary. Before you start, you need:
>
> * A Linux or macOS runner with Node.js 22 or later.
> * A [Tuner API key](https://docs.usetuner.ai/docs/getting-started/api-keys.md#create-a-tuner-api-key), stored as a secret in your CI tool.
> * The agent's [Agent Remote ID](https://docs.usetuner.ai/docs/getting-started/api-keys.md#find-your-agent-remote-id).
> * [Inbound](https://docs.usetuner.ai/docs/simulation/inbound/setup.md) or [outbound](https://docs.usetuner.ai/docs/simulation/outbound.md) simulation set up for the agent.
> * Scenarios with a shared tag, such as `smoke`, in the [Scenario Library](https://docs.usetuner.ai/docs/simulation/scenarios.md).

## Deploy first, then test

Deploy the change to a staging agent first, then run Tuner after the deploy job, because a simulation calls your agent as it is deployed at that moment. See [Deploy first, then test](https://docs.usetuner.ai/docs/simulation/ci/github-actions#deploy-first-then-test).

## Exit codes

Any non-zero exit code fails the build. See [Exit codes](https://docs.usetuner.ai/docs/simulation/cli.md#exit-codes) for what each code means.

Exit `3` means Tuner couldn't finish the run. The GitHub Action passes the build on `3` with a warning, and you can do the same by accepting it in your command:

```bash theme={null}
npx @usetuner.ai/cli sim run --tag smoke || [ $? -eq 3 ]
```

Drop `|| [ $? -eq 3 ]` to fail the build on `3` as well.

## Send the commit and branch

Pass `--meta` so each run shows which change it tested. See [Add run metadata](https://docs.usetuner.ai/docs/simulation/cli.md#add-run-metadata) and [See which commit a run tested](https://docs.usetuner.ai/docs/simulation/run-statuses.md#see-which-commit-a-run-tested).

Use the variables your CI tool sets:

| Key | GitLab CI | CircleCI | Jenkins |
| - | - | - | - |
| `commit` | `CI_COMMIT_SHA` | `CIRCLE_SHA1` | `GIT_COMMIT` |
| `branch` | `CI_COMMIT_REF_NAME` | `CIRCLE_BRANCH` | `BRANCH_NAME` in a Multibranch Pipeline |
| `repo_url` | `CI_PROJECT_URL` | `CIRCLE_REPOSITORY_URL`, on GitHub and Bitbucket Cloud | `GIT_URL` |
| `pr_url` | `CI_MERGE_REQUEST_PROJECT_URL` and `CI_MERGE_REQUEST_IID`, in merge request pipelines | `CIRCLE_PULL_REQUEST`, on GitHub and Bitbucket Cloud | Left out of the example |

A tool doesn't set every variable in every pipeline. The examples add a `--meta` pair only when its variable has a value, with `${VARIABLE:+...}`.

## Examples

Each example deploys first and then runs the simulations. It passes the build on exit `3` and sends run metadata.

Replace the deploy step and the agent ID with your own, and keep the job's timeout above `--timeout`. The examples run the CLI with `npx`. To pin a version, add `@x.y.z` to the package name.

> [tab] GitLab CI
>
> Add the key in your project under **Settings > CI/CD > Variables > Add variable**. Name it `TUNER_API_KEY` and set **Visibility** to **Masked**.
>
> ```yaml theme={null}
> stages:
>   - deploy
>   - test
>
> deploy-staging:
>   stage: deploy
>   script:
>     - ./scripts/deploy-staging.sh # replace with your own deploy
>
> tuner-simulations:
>   stage: test
>   image: node:22
>   timeout: 40m
>   variables:
>     TUNER_AGENT_ID: "your-staging-agent-remote-id"
>   script:
>     - >
>       npx @usetuner.ai/cli sim run --tag smoke --timeout 30m
>       --meta commit=$CI_COMMIT_SHA
>       --meta branch=$CI_COMMIT_REF_NAME
>       --meta repo_url=$CI_PROJECT_URL
>       ${CI_MERGE_REQUEST_IID:+--meta pr_url=$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID}
>   allow_failure:
>     exit_codes:
>       - 3
> ```
>
> The `allow_failure` block passes the pipeline when the CLI exits `3`.

> [tab] CircleCI
>
> Add the key in your project under **Project Settings > Environment Variables > Add Variable**. Name it `TUNER_API_KEY`.
>
> ```yaml theme={null}
> version: 2.1
>
> jobs:
>   deploy-staging:
>     docker:
>       - image: cimg/node:lts
>     steps:
>       - checkout
>       - run: ./scripts/deploy-staging.sh # replace with your own deploy
>
>   tuner-simulations:
>     docker:
>       - image: cimg/node:lts
>     environment:
>       TUNER_AGENT_ID: your-staging-agent-remote-id
>     steps:
>       - run:
>           name: Run Tuner simulations
>           no_output_timeout: 35m
>           command: |
>             npx @usetuner.ai/cli sim run --tag smoke --timeout 30m \
>               --meta commit="$CIRCLE_SHA1" \
>               ${CIRCLE_BRANCH:+--meta branch="$CIRCLE_BRANCH"} \
>               ${CIRCLE_REPOSITORY_URL:+--meta repo_url="$CIRCLE_REPOSITORY_URL"} \
>               ${CIRCLE_PULL_REQUEST:+--meta pr_url="$CIRCLE_PULL_REQUEST"} \
>               || [ $? -eq 3 ]
>
> workflows:
>   test-staging:
>     jobs:
>       - deploy-staging
>       - tuner-simulations:
>           requires:
>             - deploy-staging
> ```
>
> CircleCI stops a step that prints nothing for 10 minutes by default. `no_output_timeout` raises that limit above `--timeout`, because the CLI can be quiet while it waits.

> [tab] Jenkins
>
> Add the key as a **Secret text** credential with the ID `tuner-api-key`. The example needs a Multibranch Pipeline for `BRANCH_NAME`, the Docker Pipeline plugin for the `docker` agent, and the Git plugin for `GIT_COMMIT` and `GIT_URL`.
>
> ```groovy theme={null}
> pipeline {
>   agent none
>   stages {
>     stage('Deploy to staging') {
>       agent any
>       steps {
>         sh './scripts/deploy-staging.sh' // replace with your own deploy
>       }
>     }
>     stage('Tuner simulations') {
>       agent { docker { image 'node:22' } }
>       options { timeout(time: 40, unit: 'MINUTES') }
>       environment {
>         TUNER_API_KEY = credentials('tuner-api-key')
>         TUNER_AGENT_ID = 'your-staging-agent-remote-id'
>       }
>       steps {
>         sh '''
>           npx @usetuner.ai/cli sim run --tag smoke --timeout 30m \
>             --meta commit="$GIT_COMMIT" \
>             ${BRANCH_NAME:+--meta branch="$BRANCH_NAME"} \
>             ${GIT_URL:+--meta repo_url="$GIT_URL"} \
>             || [ $? -eq 3 ]
>         '''
>       }
>     }
>   }
> }
> ```
>
> Use single quotes around the `sh` script, as above, so the shell reads the key and Groovy never prints it.

> [tab] Shell script
>
> Use this in any tool that runs a shell. It passes the build on exit `3` and fails it on every other non-zero code. Send `branch` and `repo_url` the same way as in the other examples, with your tool's variables.
>
> ```bash theme={null}
> #!/bin/sh
> # TUNER_API_KEY and TUNER_AGENT_ID come from your CI tool's secrets.
> npx @usetuner.ai/cli sim run --tag smoke --timeout 30m \
>   --meta commit="$(git rev-parse HEAD)"
> status=$?
>
> if [ "$status" -eq 3 ]; then
>   echo "Tuner couldn't finish the run. Not failing the build."
>   exit 0
> fi
> exit "$status"
> ```

## Read the result

The job log shows each Scenario's result, a summary line and a link to the run. See [Read the results](https://docs.usetuner.ai/docs/simulation/cli.md#read-the-results).

To keep the result as a file, add `--output json` and save stdout. Store `tuner-result.json` as a job artifact in your CI tool. See [Use the results in scripts](https://docs.usetuner.ai/docs/simulation/cli.md#use-the-results-in-scripts).

```bash theme={null}
npx @usetuner.ai/cli sim run --tag smoke --output json > tuner-result.json
```

## Cancel and time out

Set `--timeout` below your job's own timeout, as the examples do. When the timeout runs out, the CLI cancels the run and the agent is free for the next one.

When someone cancels a job, the CLI cancels the run only if the CI tool sends it a stop signal. GitLab, CircleCI and Jenkins don't document a stop signal for a canceled job, so don't rely on it. If a run is left behind, see [Cancel a run](https://docs.usetuner.ai/docs/simulation/cli.md#cancel-a-run).

> [!TIP]
>
> If your tool does send SIGINT or SIGTERM to the step's shell, start the command with `exec`, as in `exec npx @usetuner.ai/cli sim run --tag smoke`. The shell then hands the signal to the CLI. GitHub Actions works this way.

## Troubleshooting

> [accordion] No API key or No agent
>
> The CLI found no `TUNER_API_KEY` or `TUNER_AGENT_ID`. Check the secret's name and that the job can read it. Some tools hide secrets from pipelines on unprotected branches or from forks.

> [accordion] The agent already has a run in progress
>
> Another job is testing the same agent. Run one Tuner job at a time for each agent, or cancel the other run. See [Cancel a run](https://docs.usetuner.ai/docs/simulation/cli.md#cancel-a-run).

> [accordion] The step stops with no output
>
> Your CI tool has a limit on a step that prints nothing. Raise it above `--timeout`. In CircleCI, that is `no_output_timeout`.

> [accordion] The commit isn't a link in Tuner
>
> Tuner links the commit and branch only when `repo_url` starts with `https://`. A Git URL that starts with `git@` shows as plain text.

## Limits

| Limit | Value |
| - | - |
| Default `--timeout` | 60 minutes |
| Scenarios per run | Up to 100 |
| Runs in progress for one agent | 1 |

## Next steps

> [card] [GitHub Actions](https://docs.usetuner.ai/docs/simulation/ci/github-actions)
>
> A pass/fail check, a pull request comment and a job summary on GitHub.

> [card] [CLI](https://docs.usetuner.ai/docs/simulation/cli.md)
>
> Every command, the exit codes and the JSON output.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.