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
        • Kotest
        • 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)
      • OpenAI Codex Support
    • 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

BitBucket Pipelines

Last updated 9 days ago

Trunk Flaky Tests integrates with your CI by adding a step in your BitBucket Pipelines to upload tests with the Trunk Uploader CLI.

Before you start on these steps, see the Test Frameworks 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 app.trunk.io 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

Store the Trunk slug and API token obtained in the previous step in your BitBucket as a new variable named TRUNK_ORG_SLUG and TRUNK_TOKEN respectively.

Upload to Trunk

Add an after-script 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 stable branches, for example, main, master, or develop.

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

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.

Learn more about detection

Add Uploader to Testing Pipelines

The following is an example of a workflow 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 JUnit XML files the uploader needs, see the instructions for your test framework in the Test Frameworks docs.

image: <BITBUCKET_IMAGE>

pipelines:
  default:
    - step:
       # ... omitted setup and build steps 
    - step:
        name: Run Tests and Upload Results
        script:
          - <COMMAND TO RUN TESTS>
        after-script:
          # This ensures trunk upload runs even if the test script fails
          - |
            curl -fsSLO --retry 3 https://trunk.io/releases/trunk
            chmod +x ./trunk
            ./trunk flakytests upload --junit-paths "**/junit.xml" \
              --org-url-slug $TRUNK_ORG_SLUG \
              --token $TRUNK_TOKEN
image: <BITBUCKET_IMAGE>

pipelines:
  default:
    - step:
       # ... omitted setup and build steps 
    - step:
        name: Run Tests and Upload Results
        script:
          - <COMMAND TO RUN TESTS>
        after-script:
          # This ensures trunk upload runs even if the test script fails
          - |
            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: <BITBUCKET_IMAGE>

pipelines:
  default:
    - step:
       # ... omitted setup and build steps 
    - step:
        name: Run Tests and Upload Results
        script:
          - <COMMAND TO RUN TESTS>
        after-script:
          # This ensures trunk upload runs even if the test script fails
          - |
            curl -fsSLO --retry 3 https://trunk.io/releases/trunk
            chmod +x ./trunk
            ./trunk flakytests upload --xcresult-path <XCRESULT_PATH> \
              --org-url-slug $TRUNK_ORG_SLUG \
              --token $TRUNK_TOKEN
image: <BITBUCKET_IMAGE>

pipelines:
  default:
    - step:
       # ... omitted setup and build steps 
    - step:
        name: Run Tests and Upload Results
        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.

You can do this by omitting the artifacts definitions in the test steps of your configuration. Learn more about artifacts in BitBucket Pipelines.

Have questions?

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

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.