Trunk Analytics CLI
Trunk detects and tracks flaky tests in your repos by receiving uploads from your test runs in CI, uploaded from the Trunk Analytics CLI. These uploads happen in the CI jobs used to run tests in your nightly CI, post-commit jobs, and PR checks.
Guides
If you're setting up Trunk Flaky Tests for the first time, you can follow the guides for your CI provider and test framework.
The CLI should be downloaded as part of your test workflow in your CI system. The automatic launcher is platform agnostic and will download the latest version of the uploader for your platform.
Manual Download
You can find the list of releases on the GitHub release page. We provide executables for Linux and OS X. It’s a single file inside a tar and upon downloading the tar you will find a single binary - trunk-analytics-cli to use.
SKU="trunk-analytics-cli-x86_64-unknown-linux.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cliSKU="trunk-analytics-cli-aarch64-unknown-linux.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cliSKU="trunk-analytics-cli-aarch64-apple-darwin.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cliSKU="trunk-analytics-cli-x86_64-apple-darwin.tar.gz"
curl -fL --retry 3 \
"https://github.com/trunk-io/analytics-cli/releases/latest/download/${SKU}" \
| tar -xz
chmod +x trunk-analytics-cliOrganization Slug and Token
The CLI requires your Trunk organization slug and token passed through --org-url-slug and --token to upload results to the correct organzation.
You can find your organization slug and token by going to Settings > Manage > Organization.




Uploading Test Results
Trunk accepts uploads in three main report formats, XML, Bazel Event Protocol JSONs, and XCode XCResult paths. You can upload each of these test report formats using the ./trunk flakytest upload command like this:
Trunk can accept JUnit XMLs through the --junit-paths argument:
./trunk-analytics-cli upload --junit-paths "test_output.xml" \
--org-url-slug <TRUNK_ORG_SLUG> \
--token $TRUNK_API_TOKENTrunk can accept Bazel through the --bazel-bep-path argument:
./trunk flakytests upload --bazel-bep-path <BEP_JSON_PATH> \
--org-url-slug <TRUNK_ORG_SLUG> \
--token $TRUNK_API_TOKENTrunk can accept XCode through the --xcresult-path argument:
./trunk flakytests upload --xcresult-path <XCRESULT_PATH> \
--org-url-slug <TRUNK_ORG_SLUG> \
--token $TRUNK_API_TOKENRunning and Quarantining Tests
You can also execute tests and upload results to Trunk in a single step using the test command to wrap your test command.
This is especially useful for Quarantining, where the Trunk CLI will override the exit code of the test command if all failures can be quarantined, preventing flaky tests from failing your builds in CI.
Trunk can accept JUnit XMLs through the --junit-paths argument:
./trunk-analytics-cli test --junit-paths "test_output.xml" \
--org-url-slug <TRUNK_ORG_SLUG> \
--token $TRUNK_API_TOKEN \
<YOUR_TEST_COMMAND>Trunk can accept Bazel through the --bazel-bep-path argument:
./trunk-analytics-cli test --bazel-bep-path <BEP_JSON_PATH> \
--org-url-slug <TRUNK_ORG_SLUG> \
--token $TRUNK_API_TOKEN \
<YOUR_TEST_COMMAND>Trunk can accept XCode through the --xcresult-path argument:
./trunk-analytics-cli test --xcresult-path <XCRESULT_PATH> \
--org-url-slug <TRUNK_ORG_SLUG> \
--token $TRUNK_API_TOKEN \
<YOUR_TEST_COMMAND>Upload failure vs test failure
We use the SOFTWARE exit code (70) if the upload fails.
If you use the test command and tests fail without the failures being quarantined, we return the provided exit code from the wrapped execution.
If you use the upload command, we return exit code FAILURE or the exit code provided with the --test_process_exit_code argument.
Validating reports locally
You can validate the test reports produced by your test frameworks before you set up Trunk in your CI jobs. This is currently only available for XML reports.
You can run the validate command like this:
./trunk-analytics-cli validate --junit-paths "test_output.xml"The validate command will output any problems with your reports so you can address them before setting up Trunk in CI.
Validating the following 1 files:
File set matching junit.xml:
junit.xml
junit.xml - 1 test suites, 0 test cases, 0 validation errors
All 1 files are valid! ✅
Navigate to https://app.trunk.io/onboarding?intent=flaky+tests to continue using Trunk Flaky Tests! 🚀🧪Using custom CI systems
The CLI is preconfigured to work with a set CI Providers but can be used with any CI system by passing Environment Variables to the uploader.
More information on using Other CI Providers is documented here.
Full command reference
The trunk command-line tool can upload and analyze test results. The trunk-analytics-cli command accepts the following subcommands:
trunk-analytics-cli upload
Upload data to Trunk Flaky Tests.
trunk-analytics-cli validate
Validates if the provided JUnit XML files and prints any errors.
trunk-analytics-cli test <COMMAND>
Runs tests using the provided command, uploads results, checks whether the failures are quarantined tests, and correct the exit code based on that.
The upload and test commands accept the following options:
--junit-paths <JUNIT_PATHS>
Path to the test output files. File globs are supported. Remember to wrap globs in "" quotes
--bazel-bep-path <BEP_JSON_PATH>
Path to a JSON serialized Bazel Build Event Protocol. Trunk will use the BEP file to locate test reports. Your test frameworks must still output compatible report formats.
--xcresult-path <XCRESULT_PATH>
Path to a .xcresult directory, which contains test reports from xcodebuild.
--org-url-slug <ORG_URL_SLUG>
Trunk Organization slug, from the Settings page.
--token <TOKEN>
Trunk Organization (not repo) token, from the Settings page. Defaults to the TRUNK_API_TOKEN variable.
-h, --help
Additional detailed description of the upload command.
--repo-root
Path to the repository root. Defaults to the current directory.
--repo-url <REPO_URL>
Value to override URL of repository. Optional.
--repo-head-sha <REPO_HEAD_SHA>
Value to override SHA of repository head. Optional.
--repo-head-branch <REPO_HEAD_BRANCH>
Value to override branch of repository head. Optional.
--repo-head-commit-epoch <REPO_HEAD_COMMIT_EPOCH>
Value to override commit epoch of repository head. Optional.
--codeowners-path <CODEOWNERS_PATH>
Value to override CODEOWNERS file or directory path. Optional.
--allow-empty-test-results
Don't fail commands if test results are empty or missing. Use it when you sometimes skip all tests for certain CI jobs. Defaults to true.
--variant <VARIANT_NAME>
Upload tests to a specific variant group. Optional.
--test-process-exit-code <EXIT_CODE>
Specify the exit code of the test previously run. This is used by the upload command to identify errors that happen outside of the context of the test execution (such as build errors).
Memory Overhead
Running tests via trunk-analytics-cli test adds negligible memory overhead.
This subcommand is a thin wrapper around your existing test command and doesn't modify or parallelize test execution.
During execution, it simply:
Runs your provided test command directly.
Records start and end times.
Captures the exit code for quarantine decisions.
You can safely run the CLI even with large or memory-intensive suites, without risking additional OOMs in your CI agents.
Last updated

