Not using GitHub for source control?Flaky Test support for source control providers like GitLab and BitBucket is still experimental. If you’re using a source control provider other than GitHub, contact us to get started.
Setup steps
Work through the steps below in order. Once you’ve finished the last one, you’re set up — navigate to app.trunk.io to see your results.Trunk Organization Slug and Token
Before setting up uploads to Trunk, you must sign in to app.trunk.io and obtain your Trunk organization slug, your token, and the ID of the test collection to upload to.Trunk Slug
You can find your organization slug under Settings → Organization → General. You’ll use it in your upload command in a later step.Trunk Token
You can find your token under Settings → Organization → General, in the API section. Since this is a secret, do not leak it publicly. Ensure you get your organization token, not your project/repo token.Test Collection ID
Create a test collection under Flaky Tests → Collections, or open an existing one, and copy its ID from the collection’s page header. It is not a secret, so you can include it directly in your upload command.Store the Trunk Token as a Project Variable
Store your Trunk API token as an Evergreen project variable so tasks can read it as an expansion.- Open your project’s settings in Evergreen and go to Variables.
- Add a variable named
trunk_tokenwith your Trunk organization API token as the value. - Check Private so the value is redacted from the projects page, the API, and task logs.
- Save the settings.
${trunk_token}.
Upload to Trunk
Add an upload step to your project configuration that runs after your tests. The Trunk CLI detects Evergreen from theEVR_TASK_ID environment variable, which Evergreen sets for every command, and reads the build details from the CLI’s custom CI variables, which the upload step sets from Evergreen expansions.
Apart from
EVR_TASK_ID, Evergreen puts no build details into a command’s environment. The branch, pull request number, and task details are expansions, so the upload step must map them to the variables below in its env. Without them, Trunk can’t tell pull request, merge queue, and mainline runs apart, and can’t link uploads to their Evergreen tasks.Variables to Set
<EVERGREEN_UI_URL> is the address of your Evergreen UI, for example https://spruce.mongodb.com. The example uses Evergreen’s ${a|*b} syntax, which falls back to expansion b when a is not set. It reaches only one level deep, so the script sets COMMIT_BRANCH itself for mainline builds and manual patches. A manual patch gets evergreen-patch/${version_id}, so its results are not counted as runs on your stable branch.
Example Project Configuration
The following example defines an upload function and calls it frompost, which Evergreen runs after every task, including tasks whose tests failed. For tasks in a task group, call it from teardown_task instead. Note: you must either run the CLI from the repo root when uploading test results or pass a --repo-root argument.
To find out how to produce the report files the uploader needs, see the instructions for your test framework in the Test Frameworks docs.
Evergreen replaces every
${...} in a script with an expansion before the shell runs it, and an unknown expansion becomes an empty string. Refer to shell variables in the script as $NAME, not ${NAME}.
The examples use the Linux x64 binary. If your hosts run on a different platform, see the Trunk Analytics CLI page for all available platform downloads.
See the Trunk Analytics CLI for all available command line arguments and usage.
Stale files
Ensure you report every test run in CI and clean up stale files produced by your test framework. If you’re reusing hosts and using a glob like**/junit.xml to upload tests, stale files not cleaned up will be included in the current test run, throwing off detection of flakiness. You should clean up all your results files after every upload step.
Validate Your Uploads
Once a mainline build has run, navigate to app.trunk.io and confirm Trunk received your results.- The Uploads tab lists every report Trunk has ingested, with status and any warnings (missing file paths, malformed XML, and so on).
- The Tests tab shows individual test cases once an upload has been processed.
trunk_token project variable is set and the org slug and collection ID in your project configuration are correct.