LogoLogo
SlackLogin
  • Overview
    • Welcome
  • Setup & Configuration
    • Connecting to Trunk
    • Managing Your Organization
      • GitHub App Permissions
  • Integration with Slack
  • Flaky Tests (Beta)
    • Overview
    • Get Started
      • Test Frameworks
        • Android
        • Bazel
        • Behave
        • cargo-nextest
        • Cypress
        • Dart Test
        • Go
        • GoogleTest
        • Gradle
        • Jasmine
        • Jest
        • Karma
        • Maven
        • minitest
        • Mocha
        • Nightwatch
        • NUnit
        • Pest
        • PHPUnit
        • Playwright
        • Pytest
        • Robot Framework
        • RSpec
          • RSpec (Manual Uploads)
        • Swift Testing
        • Vitest
        • XCTest
        • Other Test Frameworks
      • CI Providers
        • Azure DevOps Pipelines
        • BitBucket Pipelines
        • Buildkite
        • CircleCI
        • Drone CI
        • GitHub Actions
        • GitLab
        • Jenkins
        • Semaphore CI
        • TeamCity
        • Travis CI
        • Other CI Providers
    • Dashboard
    • Flaky Test Detection
    • Quarantining
    • PR Comments
    • Ticketing Integrations
      • Jira Integration
      • Linear Integration
      • Other Ticketing Platforms
    • Webhooks
      • Slack Integration
      • Microsoft Teams Integration
      • GitHub Issues Integration
      • Linear Integration
    • Uploader CLI Reference
  • Merge Queue
    • Overview
    • How does it work?
    • Setup
      • Quick Start
      • Settings
      • Integration for Slack
    • Concepts and Optimizations
      • Predictive Testing
      • Optimistic Merging
      • Pending Failure Depth
      • Anti-Flake Protection
      • Batching
      • Parallel Queues
        • Bazel
        • Nx
        • API
      • FAQ
    • Priority
    • Managing Merge Queue
      • Using the Merge UI
      • Metrics
      • Command Line
    • Webhooks
    • Reference
  • Code Quality
    • Overview
    • Why Metalinters?
      • How does it work?
      • Why Code Quality?
    • Setup & Installation
      • Initialize Trunk
      • Local Linting
      • Linting in CI
      • Nightly Report (Deprecated)
    • IDE Integration
      • VSCode
      • Neovim
      • GitHub Codespaces
    • Linters
      • Supported Linters
        • Actionlint
        • Ansible-lint
        • Autopep8
        • Bandit
        • Biome
        • Black
        • Brakeman
        • buf
        • Buildifier
        • cfnlint
        • Checkov
        • circleci
        • ClangFormat
        • clang-tidy
        • Clippy
        • cmake-format
        • codespell
        • cspell
        • cue-fmt
        • dart
        • deno
        • Detekt
        • djlint
        • dotenv-linter
        • dotnet-format
        • dustilock
        • ESLint
        • Flake8
        • git-diff-check
        • Gitleaks
        • Gofmt
        • gofumpt
        • goimports
        • gokart
        • golangci-lint
        • golines
        • google-java-format
        • graphql-schema-linter
        • hadolint
        • haml-lint
        • isort
        • iwyu
        • ktlint
        • kube-linter
        • markdown-link-check
        • markdown-table-prettify
        • Markdownlint
        • markdownlint-cli2
        • mypy
        • nancy
        • nixpkgs-fmt
        • opa
        • OSV-Scanner
        • Oxipng
        • perlcritic
        • perltidy
        • php-cs-fixer
        • phpstan
        • pmd
        • pragma-once
        • pre-commit-hooks
        • Prettier
        • prisma
        • psscriptanalyzer
        • Pylint
        • pyright
        • regal
        • remark-lint
        • renovate
        • rome
        • rubocop
        • Ruff
        • rufo
        • rustfmt
        • scalafmt
        • semgrep
        • ShellCheck
        • shfmt
        • sort-package-json
        • sourcery
        • sql-formatter
        • SQLFluff
        • sqlfmt
        • squawk
        • standardrb
        • stringslint
        • stylelint
        • stylua
        • SVGO
        • swiftformat
        • swiftlint
        • taplo
        • Terraform
        • terragrunt
        • terrascan
        • TFLint
        • tfsec
        • tofu
        • Trivy
        • Trufflehog
        • txtpbfmt
        • vale
        • Yamllint
        • yapf
      • Run Linters
      • Manage Linters
      • Configure Linters
      • Ignoring Issues and Files
      • Custom Linters
      • Shared Configs
      • Upgrades
    • Debugging
    • Licensing
  • CLI & API References
    • CLI Reference
      • Install
      • Getting Started
        • Code Quality
        • Merge Queue
        • Flaky Tests
        • Tools
        • Actions
          • Git Hooks
        • Announce
      • Compatibility
      • Caching
      • Commands Reference
        • Code Quality
        • Actions
        • Merge
      • Configuration
        • Plugins
          • Share Config Between Codebases
          • Exporting Linter Configs
        • Runtimes
        • Tools
        • Lint
          • Definitions
          • Commands
          • Output
          • Output Parsing
          • Files and Caching
          • Dependencies
          • Auto-Enable
        • Actions
          • Notifications
          • Logging and Troubleshooting
        • Merge
        • Telemetry
        • Per User Overrides
    • API Reference
      • Flaky Tests
      • Merge Queue
      • Webhooks Reference
  • Pricing & Security
    • Security
  • Billing
  • Community & Support
  • Links
    • Open App
    • Slack Community
    • Changelog
    • Feature Requests
On this page
  • Checklist
  • Trunk Organization Slug and Token
  • Add the Trunk Token as a Secret
  • Upload to Trunk
Edit on GitHub
  1. Flaky Tests (Beta)
  2. Get Started
  3. CI Providers

GitLab

Configure Flaky Tests using GitLab CI

Last updated 1 day ago

Trunk Flaky Tests integrates with your CI by adding a step in your GitLab CI/CD pipelines to upload tests with the .

Before you start on these steps, see the docs for instructions on producing a Trunk-compatible output for your test framework.

Checklist

By the end of this guide, you should achieve the following.

After completing these checklist items, you'll be integrated with Trunk.

Trunk Organization Slug and Token

Before setting up uploads to Trunk, you must sign in to and obtain your Trunk organization slug and token.

Trunk Slug

You can find your organization slug under Settings > Organization > Manage > Organization Name > Slug. You'll save this as a variable in CI in a later step.

Trunk Token

You can find your token under Settings > Organization > Manage > Organization API Token > View Organization API Token > View. Since this is a secret, do not leak it publicly. Ensure you get your organization token, not your project/repo token.

Add the Trunk Token as a Secret

Upload to Trunk

Trunk can also detect test flakes on PR and merge branches. To best detect flaky tests, it is recommended to upload test results from stable, PR, and merge branch CI runs.

Example GitLab Pipeline

The following is an example of a GitLab pipeline step to upload test results after your tests run. Note: you must either run trunk 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.

image: node:latest

stages:         # List of stages for jobs, and their order of execution
  - test
  - flaky-tests

unit_test_job:   # This job runs the tests
  stage: test    
  script: ...

upload_test_results: # This job uploads tests results run in the last stage to Trunk.io
  stage: flaky-tests
  script:
    - curl -fsSLO --retry 3 https://trunk.io/releases/trunk && chmod +x ./trunk
    - ./trunk flakytests upload --junit-paths "<XML_GLOB_PATH>" --org-url-slug <TRUNK_ORG_SLUG> --token $TRUNK_TOKEN
image: node:latest

stages:         # List of stages for jobs, and their order of execution
  - test
  - flaky-tests

unit_test_job:   # This job runs the tests
  stage: test    
  script: ...

upload_test_results: # This job uploads tests results run in the last stage to Trunk.io
  stage: flaky-tests
  script:
    - curl -fsSLO --retry 3 https://trunk.io/releases/trunk && chmod +x ./trunk
    - ./trunk flakytests upload --bazel-bep-path <BEP_JSON_PATH> --org-url-slug <TRUNK_ORG_SLUG> --token $TRUNK_TOKEN
image: node:latest

stages:         # List of stages for jobs, and their order of execution
  - test
  - flaky-tests

unit_test_job:   # This job runs the tests
  stage: test    
  script: ...

upload_test_results: # This job uploads tests results run in the last stage to Trunk.io
  stage: flaky-tests
  script:
    - curl -fsSLO --retry 3 https://trunk.io/releases/trunk && chmod +x ./trunk
    - ./trunk flakytests upload --xcresults-path <XCRESULT_PATH> --org-url-slug <TRUNK_ORG_SLUG> --token $TRUNK_TOKEN
image: node:latest

stages:         # List of stages for jobs, and their order of execution
  - test

unit_test_job:   # This job runs the tests and uploads the results to Trunk.io
  stage: test    
  script:
    - TRUNK_ORG_URL_SLUG=$TRUNK_ORG_SLUG TRUNK_API_TOKEN=$TRUNK_TOKEN bundle exec rspec

See the Uploader CLI Reference 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 test runners 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.

Have questions?

Store the Trunk slug and API token obtained in the previous step in your GitLab CI/CD pipelines as new named TRUNK_ORG_SLUG and TRUNK_TOKEN respectively.

Add an upload_test_results step after running tests in each of your CI jobs that run tests. This should be minimally all jobs that run on pull requests, as well as from jobs that run on your main or , for example, main, master, or develop.

It is important to upload test results from CI runs on , such as main, master, or develop. This will give you a stronger signal about the health of your code and tests.

To find out how to produce the report files the uploader needs, see the instructions for your test framework in the docs.

Join us and 1500+ fellow engineers to get help with Trunk.

GitLab Variables
Learn more about detection
Test Frameworks
on Slack
Trunk Uploader CLI
Test Frameworks
app.trunk.io
stable branches
stable branches

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, to get started.

contact us