Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
"flaky-tests/get-started/ci-providers/droneci",
"flaky-tests/get-started/ci-providers/github-actions",
"flaky-tests/get-started/ci-providers/gitlab",
"flaky-tests/get-started/ci-providers/google-cloud-build",
"flaky-tests/get-started/ci-providers/jenkins",
"flaky-tests/get-started/ci-providers/otherci",
"flaky-tests/get-started/ci-providers/semaphoreci",
Expand Down
2 changes: 1 addition & 1 deletion flaky-tests/get-started/ci-providers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Flaky Test support for source control providers like GitLab and BitBucket is sti

### Quickstart

<table data-view="cards" data-full-width="false"><thead><tr><th></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Atlassian Bamboo</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/atlassian-bamboo">atlassian-bamboo</a></td><td></td></tr><tr><td><strong>Azure DevOps Pipelines</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/azure-devops-pipelines">azure-devops-pipelines</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-e25fd26aa79fb9b2eed0d2dcd87b1a5914dff23d%2Fazure.png?alt=media">azure.png</a></td></tr><tr><td><strong>BitBucket Pipelines</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/bitbucket-pipelines">bitbucket-pipelines</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-f7bb3441ba62da7dc26dd780ad0ea8b12c6a9d5b%2Fbitbucket.png?alt=media">bitbucket.png</a></td></tr><tr><td><strong>BuildKite</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/buildkite">buildkite</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-13bce185a370e3ad7386afc527575e6049f6c90c%2Fbuildkite.png?alt=media">buildkite.png</a></td></tr><tr><td><strong>CircleCI</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/circleci">circleci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-29c2601d74f7bb842edccefda703e1c93cafe386%2Fcircle-ci.png?alt=media">circle-ci.png</a></td></tr><tr><td><strong>Drone CI</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/droneci">droneci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-8e6723931dcb17d4c7c040feb2139b68e76ce9a9%2Fdrone.png?alt=media">drone.png</a></td></tr><tr><td><strong>GitHub Actions</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/github-actions">github-actions</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-39bf1729c8521770c91ff6f969a0cad8557eda90%2Fgithub.png?alt=media">github.png</a></td></tr><tr><td><strong>Gitlab</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/gitlab">gitlab</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-159f50caada873e4a221f14845fb411ddb134a3d%2Fgitlab.png?alt=media">gitlab.png</a></td></tr><tr><td><strong>Jenkins</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/jenkins">jenkins</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-f23f9fe36af0f5d1941285bfc528aa9a5fff1b1b%2Fjenkins.png?alt=media">jenkins.png</a></td></tr><tr><td><strong>Semaphore</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/semaphoreci">semaphoreci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-f86249ac586cebdc0e2f7854126051b7e51a6e9c%2Fsemaphore.png?alt=media">semaphore.png</a></td></tr><tr><td><strong>TeamCity</strong></td><td></td><td><a href="https://github.com/trunk-io/docs/blob/main/flaky-tests/get-started/ci-providers/broken-reference/README">https://github.com/trunk-io/docs/blob/main/flaky-tests/get-started/ci-providers/broken-reference/README.md</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-b3d36f21bb85001be0fa7ec1ba648f0c169202b7%2Fteamcity.png?alt=media">teamcity.png</a></td></tr><tr><td><strong>Travis CI</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/travisci">travisci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-4d1125ee24d6189434ed3ca83f411a3dc6e1ca12%2Ftravis.png?alt=media">travis.png</a></td></tr><tr><td><strong>Other CI Providers</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/otherci">otherci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-3d5eaefed10f481da930070b192d96463c765041%2Fother.png?alt=media">other.png</a></td></tr></tbody></table>
<table data-view="cards" data-full-width="false"><thead><tr><th></th><th data-hidden></th><th data-hidden data-card-target data-type="content-ref"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td><strong>Atlassian Bamboo</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/atlassian-bamboo">atlassian-bamboo</a></td><td></td></tr><tr><td><strong>Azure DevOps Pipelines</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/azure-devops-pipelines">azure-devops-pipelines</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-e25fd26aa79fb9b2eed0d2dcd87b1a5914dff23d%2Fazure.png?alt=media">azure.png</a></td></tr><tr><td><strong>BitBucket Pipelines</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/bitbucket-pipelines">bitbucket-pipelines</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-f7bb3441ba62da7dc26dd780ad0ea8b12c6a9d5b%2Fbitbucket.png?alt=media">bitbucket.png</a></td></tr><tr><td><strong>BuildKite</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/buildkite">buildkite</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-13bce185a370e3ad7386afc527575e6049f6c90c%2Fbuildkite.png?alt=media">buildkite.png</a></td></tr><tr><td><strong>CircleCI</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/circleci">circleci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-29c2601d74f7bb842edccefda703e1c93cafe386%2Fcircle-ci.png?alt=media">circle-ci.png</a></td></tr><tr><td><strong>Drone CI</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/droneci">droneci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-8e6723931dcb17d4c7c040feb2139b68e76ce9a9%2Fdrone.png?alt=media">drone.png</a></td></tr><tr><td><strong>Google Cloud Build</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/google-cloud-build">google-cloud-build</a></td><td></td></tr><tr><td><strong>GitHub Actions</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/github-actions">github-actions</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-39bf1729c8521770c91ff6f969a0cad8557eda90%2Fgithub.png?alt=media">github.png</a></td></tr><tr><td><strong>Gitlab</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/gitlab">gitlab</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-159f50caada873e4a221f14845fb411ddb134a3d%2Fgitlab.png?alt=media">gitlab.png</a></td></tr><tr><td><strong>Jenkins</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/jenkins">jenkins</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-f23f9fe36af0f5d1941285bfc528aa9a5fff1b1b%2Fjenkins.png?alt=media">jenkins.png</a></td></tr><tr><td><strong>Semaphore</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/semaphoreci">semaphoreci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-f86249ac586cebdc0e2f7854126051b7e51a6e9c%2Fsemaphore.png?alt=media">semaphore.png</a></td></tr><tr><td><strong>TeamCity</strong></td><td></td><td><a href="https://github.com/trunk-io/docs/blob/main/flaky-tests/get-started/ci-providers/broken-reference/README">https://github.com/trunk-io/docs/blob/main/flaky-tests/get-started/ci-providers/broken-reference/README.md</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-b3d36f21bb85001be0fa7ec1ba648f0c169202b7%2Fteamcity.png?alt=media">teamcity.png</a></td></tr><tr><td><strong>Travis CI</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/travisci">travisci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-4d1125ee24d6189434ed3ca83f411a3dc6e1ca12%2Ftravis.png?alt=media">travis.png</a></td></tr><tr><td><strong>Other CI Providers</strong></td><td></td><td><a href="/flaky-tests/get-started/ci-providers/otherci">otherci</a></td><td><a href="https://577236045-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F61Ep9MrYBkJa0Yq3zS1s%2Fuploads%2Fgit-blob-3d5eaefed10f481da930070b192d96463c765041%2Fother.png?alt=media">other.png</a></td></tr></tbody></table>
221 changes: 221 additions & 0 deletions flaky-tests/get-started/ci-providers/google-cloud-build.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
---
title: "Google Cloud Build"
description: "Configure Google Cloud Build to upload test results to Trunk Flaky Tests"
---
Trunk Flaky Tests integrates with your CI by adding a step in your Google Cloud Build configuration to upload tests with the [Trunk Analytics CLI](/flaky-tests/uploader).

<Warning>
**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**](mailto:support@trunk.io) **to get started**.
</Warning>

Before you start on these steps, see the [Test Frameworks](/flaky-tests/get-started/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.

* [ ] Get your Trunk organization slug and token
* [ ] Store your token in GCP Secret Manager
* [ ] Connect your GitHub repos to Cloud Build
* [ ] Create Cloud Build triggers for PR and push events
* [ ] Configure your `cloudbuild.yaml` to upload to Trunk
* [ ] Validate your uploads in Trunk

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](https://app.trunk.io/login?intent=flaky%20tests) 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.

### Store the Trunk Token in GCP Secret Manager

Store your Trunk API token in [GCP Secret Manager](https://console.cloud.google.com/security/secret-manager) so Cloud Build can securely access it during builds.

1. Open **GCP Console > Secret Manager**.
2. Click **Create Secret**.
3. Name the secret (for example, `trunk-api-token`) and paste your Trunk organization API token as the value.
4. Click **Create**.

You'll reference this secret in your `cloudbuild.yaml` using the `availableSecrets` and `secretEnv` fields.

### Connect GitHub Repos to Cloud Build

Ensure your GitHub repositories are connected to Cloud Build through the [Cloud Build GitHub App](https://cloud.google.com/build/docs/automating-builds/github/connect-repo-github).

1. Open **GCP Console > Cloud Build > Repositories**.
2. Connect your GitHub repository using the Cloud Build GitHub App.

### Create Cloud Build Triggers

Create two Cloud Build triggers for each repository you want to upload test results from:

1. Open **GCP Console > Cloud Build > Triggers**.
2. Create a trigger for **pull request events** — this uploads test results from PR branches.
3. Create a trigger for **push events** to your stable branch (for example, `main`) — this uploads test results from your stable branch.

<Warning>
It is important to upload test results from CI runs on [**stable branches**](/flaky-tests/detection), 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](/flaky-tests/detection)
</Warning>

### Upload to Trunk

Add an upload step in your `cloudbuild.yaml` that runs after your test steps. The Trunk CLI automatically detects Google Cloud Build when the `TRIGGER_NAME` environment variable is set.

<Warning>
Google Cloud Build does not automatically provide environment variables to build steps. You must explicitly pass the required substitution variables in your `cloudbuild.yaml` using the `env` field. Without these variables, the CLI cannot detect your CI platform or link uploads to the correct branches and pull requests.
</Warning>

#### Required Environment Variables

The following environment variables must be passed to the upload step:

| Variable | Description |
| --------------- | ----------------------------------------------------------------- |
| `TRIGGER_NAME` | Name of the Cloud Build trigger (used for CI platform detection) |
| `PROJECT_ID` | GCP project ID (used to construct the CI job link) |
| `BUILD_ID` | Unique ID of the Cloud Build run (used to construct the CI job link) |
| `BRANCH_NAME` | Git branch being built (used for push/stable branch uploads) |
| `_HEAD_BRANCH` | Head branch for PR-triggered builds |
| `_PR_NUMBER` | Pull request number for PR-triggered builds |

#### Example `cloudbuild.yaml`

The following is an example of a `cloudbuild.yaml` configuration that runs tests and uploads results to Trunk. 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 [frameworks](/flaky-tests/get-started/frameworks "mention") docs.

<Tabs>

<Tab title="XML">

```yaml
steps:
- name: gcr.io/cloud-builders/npm
id: run-tests
script: |
#!/bin/bash
set -euo pipefail
npm install
npm test
timeout: 600s
allowExitCodes: [0, 1]

- name: gcr.io/cloud-builders/gcloud
id: upload-test-results
script: |
#!/bin/bash
set -euo pipefail
curl -fL --retry 3 "https://github.com/trunk-io/analytics-cli/releases/latest/download/trunk-analytics-cli-x86_64-unknown-linux.tar.gz" | tar -xz && chmod +x trunk-analytics-cli
./trunk-analytics-cli upload \
--junit-paths "<XML_GLOB_PATH>" \
--org-url-slug <TRUNK_ORG_SLUG> \
--token "${TRUNK_API_TOKEN}"
waitFor:
- run-tests
timeout: 300s
env:
- "PROJECT_ID=${PROJECT_ID}"
- "BUILD_ID=${BUILD_ID}"
- "TRIGGER_NAME=${TRIGGER_NAME}"
- "BRANCH_NAME=${BRANCH_NAME}"
- "_HEAD_BRANCH=${_HEAD_BRANCH}"
- "_PR_NUMBER=${_PR_NUMBER}"
secretEnv: ["TRUNK_API_TOKEN"]

options:
logging: CLOUD_LOGGING_ONLY
timeout: 1200s
availableSecrets:
secretManager:
- versionName: projects/${PROJECT_ID}/secrets/<YOUR_SECRET_NAME>/versions/latest
env: TRUNK_API_TOKEN
```

</Tab>

<Tab title="Bazel">

```yaml
steps:
- name: gcr.io/cloud-builders/bazel
id: run-tests
args: ['test', '//...', '--build_event_json_file=bep.json']
timeout: 600s
allowExitCodes: [0, 1]

- name: gcr.io/cloud-builders/gcloud
id: upload-test-results
script: |
#!/bin/bash
set -euo pipefail
curl -fL --retry 3 "https://github.com/trunk-io/analytics-cli/releases/latest/download/trunk-analytics-cli-x86_64-unknown-linux.tar.gz" | tar -xz && chmod +x trunk-analytics-cli
./trunk-analytics-cli upload \
--bazel-bep-path bep.json \
--org-url-slug <TRUNK_ORG_SLUG> \
--token "${TRUNK_API_TOKEN}"
waitFor:
- run-tests
timeout: 300s
env:
- "PROJECT_ID=${PROJECT_ID}"
- "BUILD_ID=${BUILD_ID}"
- "TRIGGER_NAME=${TRIGGER_NAME}"
- "BRANCH_NAME=${BRANCH_NAME}"
- "_HEAD_BRANCH=${_HEAD_BRANCH}"
- "_PR_NUMBER=${_PR_NUMBER}"
secretEnv: ["TRUNK_API_TOKEN"]

options:
logging: CLOUD_LOGGING_ONLY
timeout: 1200s
availableSecrets:
secretManager:
- versionName: projects/${PROJECT_ID}/secrets/<YOUR_SECRET_NAME>/versions/latest
env: TRUNK_API_TOKEN
```

</Tab>

</Tabs>

<Note>
The examples above use the Linux x64 binary. If your CI runs on a different platform, see the [Trunk Analytics CLI](/flaky-tests/uploader) page for all available platform downloads.
</Note>

<Note>
**Important:** Set `allowExitCodes: [0, 1]` on your test step so the upload step runs even when tests fail. Without this, Cloud Build stops the pipeline on test failures and your results won't be uploaded.
</Note>

Replace the following placeholders in the example:

| Placeholder | Description |
| ------------------- | -------------------------------------------------------------------------------------------- |
| `<XML_GLOB_PATH>` | Glob pattern matching your JUnit XML test report files (for example, `**/junit.xml`) |
| `<TRUNK_ORG_SLUG>` | Your Trunk organization slug |
| `<YOUR_SECRET_NAME>`| The name of the secret you created in GCP Secret Manager |

See the [uploader](/flaky-tests/uploader "mention") 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.

<Check>
**Have questions?**

Join us and 1500+ fellow engineers [on Slack](https://slack.trunk.io/) to get help with Trunk.
</Check>