Skip to content

Commit 8b6f204

Browse files
samgutentagclaude
andcommitted
Add Google Cloud Build CI provider documentation for Flaky Tests
New CI provider page with setup instructions for Google Cloud Build integration, including GCP Secret Manager configuration, Cloud Build triggers, required environment variables, and example cloudbuild.yaml configurations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a8222e3 commit 8b6f204

3 files changed

Lines changed: 215 additions & 1 deletion

File tree

flaky-tests/get-started/ci-providers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ Trunk Flaky Tests integrates with your CI by adding a `Upload Test Results` step
1010

1111
### Quickstart
1212

13-
<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>Azure DevOps Pipelines</strong></td><td></td><td><a href="azure-devops-pipelines.md">azure-devops-pipelines.md</a></td><td><a href="../../../.gitbook/assets/azure.png">azure.png</a></td></tr><tr><td><strong>BitBucket Pipelines</strong></td><td></td><td><a href="bitbucket-pipelines.md">bitbucket-pipelines.md</a></td><td><a href="../../../.gitbook/assets/bitbucket.png">bitbucket.png</a></td></tr><tr><td><strong>BuildKite</strong></td><td></td><td><a href="buildkite.md">buildkite.md</a></td><td><a href="../../../.gitbook/assets/buildkite.png">buildkite.png</a></td></tr><tr><td><strong>CircleCI</strong></td><td></td><td><a href="circleci.md">circleci.md</a></td><td><a href="../../../.gitbook/assets/circle-ci.png">circle-ci.png</a></td></tr><tr><td><strong>Drone CI</strong></td><td></td><td><a href="droneci.md">droneci.md</a></td><td><a href="../../../.gitbook/assets/drone.png">drone.png</a></td></tr><tr><td><strong>GitHub Actions</strong></td><td></td><td><a href="github-actions.md">github-actions.md</a></td><td><a href="../../../.gitbook/assets/github.png">github.png</a></td></tr><tr><td><strong>Gitlab</strong></td><td></td><td><a href="gitlab.md">gitlab.md</a></td><td><a href="../../../.gitbook/assets/gitlab.png">gitlab.png</a></td></tr><tr><td><strong>Jenkins</strong></td><td></td><td><a href="jenkins.md">jenkins.md</a></td><td><a href="../../../.gitbook/assets/jenkins.png">jenkins.png</a></td></tr><tr><td><strong>Semaphore</strong></td><td></td><td><a href="semaphoreci.md">semaphoreci.md</a></td><td><a href="../../../.gitbook/assets/semaphore.png">semaphore.png</a></td></tr><tr><td><strong>TeamCity</strong></td><td></td><td><a href="broken-reference">Broken link</a></td><td><a href="../../../.gitbook/assets/teamcity.png">teamcity.png</a></td></tr><tr><td><strong>Travis CI</strong></td><td></td><td><a href="travisci.md">travisci.md</a></td><td><a href="../../../.gitbook/assets/travis.png">travis.png</a></td></tr><tr><td><strong>Other CI Providers</strong></td><td></td><td><a href="otherci.md">otherci.md</a></td><td><a href="../../../.gitbook/assets/other.png">other.png</a></td></tr></tbody></table>
13+
<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>Azure DevOps Pipelines</strong></td><td></td><td><a href="azure-devops-pipelines.md">azure-devops-pipelines.md</a></td><td><a href="../../../.gitbook/assets/azure.png">azure.png</a></td></tr><tr><td><strong>BitBucket Pipelines</strong></td><td></td><td><a href="bitbucket-pipelines.md">bitbucket-pipelines.md</a></td><td><a href="../../../.gitbook/assets/bitbucket.png">bitbucket.png</a></td></tr><tr><td><strong>BuildKite</strong></td><td></td><td><a href="buildkite.md">buildkite.md</a></td><td><a href="../../../.gitbook/assets/buildkite.png">buildkite.png</a></td></tr><tr><td><strong>CircleCI</strong></td><td></td><td><a href="circleci.md">circleci.md</a></td><td><a href="../../../.gitbook/assets/circle-ci.png">circle-ci.png</a></td></tr><tr><td><strong>Drone CI</strong></td><td></td><td><a href="droneci.md">droneci.md</a></td><td><a href="../../../.gitbook/assets/drone.png">drone.png</a></td></tr><tr><td><strong>GitHub Actions</strong></td><td></td><td><a href="github-actions.md">github-actions.md</a></td><td><a href="../../../.gitbook/assets/github.png">github.png</a></td></tr><tr><td><strong>Google Cloud Build</strong></td><td></td><td><a href="google-cloud-build.md">google-cloud-build.md</a></td><td><a href="../../../.gitbook/assets/google-cloud-build.png">google-cloud-build.png</a></td></tr><tr><td><strong>Gitlab</strong></td><td></td><td><a href="gitlab.md">gitlab.md</a></td><td><a href="../../../.gitbook/assets/gitlab.png">gitlab.png</a></td></tr><tr><td><strong>Jenkins</strong></td><td></td><td><a href="jenkins.md">jenkins.md</a></td><td><a href="../../../.gitbook/assets/jenkins.png">jenkins.png</a></td></tr><tr><td><strong>Semaphore</strong></td><td></td><td><a href="semaphoreci.md">semaphoreci.md</a></td><td><a href="../../../.gitbook/assets/semaphore.png">semaphore.png</a></td></tr><tr><td><strong>TeamCity</strong></td><td></td><td><a href="broken-reference">Broken link</a></td><td><a href="../../../.gitbook/assets/teamcity.png">teamcity.png</a></td></tr><tr><td><strong>Travis CI</strong></td><td></td><td><a href="travisci.md">travisci.md</a></td><td><a href="../../../.gitbook/assets/travis.png">travis.png</a></td></tr><tr><td><strong>Other CI Providers</strong></td><td></td><td><a href="otherci.md">otherci.md</a></td><td><a href="../../../.gitbook/assets/other.png">other.png</a></td></tr></tbody></table>
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
description: Configure Google Cloud Build to upload test results to Trunk Flaky Tests
3+
---
4+
5+
# Google Cloud Build
6+
7+
Trunk Flaky Tests integrates with your CI by adding a step in your Google Cloud Build configuration to upload tests with the [Trunk Uploader CLI](../../uploader.md).
8+
9+
{% include "../../../.gitbook/includes/not-using-github-for-source....md" %}
10+
11+
Before you start on these steps, see the [Test Frameworks](../frameworks/) docs for instructions on producing a Trunk-compatible output for your test framework.
12+
13+
### Checklist
14+
15+
By the end of this guide, you should achieve the following.
16+
17+
* [ ] Get your Trunk organization slug and token
18+
* [ ] Store your token in GCP Secret Manager
19+
* [ ] Connect your GitHub repos to Cloud Build
20+
* [ ] Create Cloud Build triggers for PR and push events
21+
* [ ] Configure your `cloudbuild.yaml` to upload to Trunk
22+
* [ ] Validate your uploads in Trunk
23+
24+
After completing these checklist items, you'll be integrated with Trunk.&#x20;
25+
26+
### Trunk Organization Slug and Token
27+
28+
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.
29+
30+
#### Trunk Slug
31+
32+
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.
33+
34+
#### Trunk Token
35+
36+
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.
37+
38+
### Store the Trunk Token in GCP Secret Manager
39+
40+
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.
41+
42+
1. Open **GCP Console > Secret Manager**.
43+
2. Click **Create Secret**.
44+
3. Name the secret (for example, `trunk-api-token`) and paste your Trunk organization API token as the value.
45+
4. Click **Create**.
46+
47+
You'll reference this secret in your `cloudbuild.yaml` using the `availableSecrets` and `secretEnv` fields.
48+
49+
### Connect GitHub Repos to Cloud Build
50+
51+
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).
52+
53+
1. Open **GCP Console > Cloud Build > Repositories**.
54+
2. Connect your GitHub repository using the Cloud Build GitHub App.
55+
56+
### Create Cloud Build Triggers
57+
58+
Create two Cloud Build triggers for each repository you want to upload test results from:
59+
60+
1. Open **GCP Console > Cloud Build > Triggers**.
61+
2. Create a trigger for **pull request events** — this uploads test results from PR branches.
62+
3. Create a trigger for **push events** to your stable branch (for example, `main`) — this uploads test results from your stable branch.
63+
64+
{% hint style="danger" %}
65+
It is important to upload test results from CI runs on [**stable branches**](../../detection.md#stable-branches), such as `main`, `master`, or `develop`. This will give you a stronger signal about the health of your code and tests.
66+
67+
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.
68+
69+
[Learn more about detection](../../detection.md)
70+
{% endhint %}
71+
72+
### Upload to Trunk
73+
74+
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.
75+
76+
{% hint style="warning" %}
77+
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.
78+
{% endhint %}
79+
80+
#### Required Environment Variables
81+
82+
The following environment variables must be passed to the upload step:
83+
84+
| Variable | Description |
85+
|----------|-------------|
86+
| `TRIGGER_NAME` | Name of the Cloud Build trigger (used for CI platform detection) |
87+
| `PROJECT_ID` | GCP project ID (used to construct the CI job link) |
88+
| `BUILD_ID` | Cloud Build build ID (used to construct the CI job link) |
89+
| `BRANCH_NAME` | Git branch being built (used for push/stable branch uploads) |
90+
| `_HEAD_BRANCH` | Head branch for PR-triggered builds |
91+
| `_PR_NUMBER` | Pull request number for PR-triggered builds |
92+
93+
#### Example `cloudbuild.yaml`
94+
95+
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.
96+
97+
To find out how to produce the report files the uploader needs, see the instructions for your test framework in the [frameworks](../frameworks/ "mention") docs.&#x20;
98+
99+
{% tabs %}
100+
{% tab title="XML" %}
101+
```yaml
102+
steps:
103+
- name: gcr.io/cloud-builders/npm
104+
id: run-tests
105+
script: |
106+
#!/bin/bash
107+
set -euo pipefail
108+
npm install
109+
npm test
110+
timeout: 600s
111+
allowExitCodes: [0, 1]
112+
113+
- name: gcr.io/cloud-builders/gcloud
114+
id: upload-test-results
115+
script: |
116+
#!/bin/bash
117+
set -euo pipefail
118+
curl -fsSLO --retry 3 https://trunk.io/releases/trunk && chmod +x ./trunk
119+
./trunk flakytests upload \
120+
--junit-paths "<XML_GLOB_PATH>" \
121+
--org-url-slug <TRUNK_ORG_SLUG> \
122+
--token "${TRUNK_API_TOKEN}"
123+
waitFor:
124+
- run-tests
125+
timeout: 300s
126+
env:
127+
- "PROJECT_ID=${PROJECT_ID}"
128+
- "BUILD_ID=${BUILD_ID}"
129+
- "TRIGGER_NAME=${TRIGGER_NAME}"
130+
- "COMMIT_SHA=${COMMIT_SHA}"
131+
- "REPO_FULL_NAME=${REPO_FULL_NAME}"
132+
- "BRANCH_NAME=${BRANCH_NAME}"
133+
- "_HEAD_BRANCH=${_HEAD_BRANCH}"
134+
- "_PR_NUMBER=${_PR_NUMBER}"
135+
secretEnv: ["TRUNK_API_TOKEN"]
136+
137+
options:
138+
logging: CLOUD_LOGGING_ONLY
139+
timeout: 1200s
140+
availableSecrets:
141+
secretManager:
142+
- versionName: projects/${PROJECT_ID}/secrets/<YOUR_SECRET_NAME>/versions/latest
143+
env: TRUNK_API_TOKEN
144+
```
145+
{% endtab %}
146+
147+
{% tab title="Bazel" %}
148+
```yaml
149+
steps:
150+
- name: gcr.io/cloud-builders/bazel
151+
id: run-tests
152+
args: ['test', '//...', '--build_event_json_file=bep.json']
153+
timeout: 600s
154+
allowExitCodes: [0, 1]
155+
156+
- name: gcr.io/cloud-builders/gcloud
157+
id: upload-test-results
158+
script: |
159+
#!/bin/bash
160+
set -euo pipefail
161+
curl -fsSLO --retry 3 https://trunk.io/releases/trunk && chmod +x ./trunk
162+
./trunk flakytests upload \
163+
--bazel-bep-path bep.json \
164+
--org-url-slug <TRUNK_ORG_SLUG> \
165+
--token "${TRUNK_API_TOKEN}"
166+
waitFor:
167+
- run-tests
168+
timeout: 300s
169+
env:
170+
- "PROJECT_ID=${PROJECT_ID}"
171+
- "BUILD_ID=${BUILD_ID}"
172+
- "TRIGGER_NAME=${TRIGGER_NAME}"
173+
- "COMMIT_SHA=${COMMIT_SHA}"
174+
- "REPO_FULL_NAME=${REPO_FULL_NAME}"
175+
- "BRANCH_NAME=${BRANCH_NAME}"
176+
- "_HEAD_BRANCH=${_HEAD_BRANCH}"
177+
- "_PR_NUMBER=${_PR_NUMBER}"
178+
secretEnv: ["TRUNK_API_TOKEN"]
179+
180+
options:
181+
logging: CLOUD_LOGGING_ONLY
182+
timeout: 1200s
183+
availableSecrets:
184+
secretManager:
185+
- versionName: projects/${PROJECT_ID}/secrets/<YOUR_SECRET_NAME>/versions/latest
186+
env: TRUNK_API_TOKEN
187+
```
188+
{% endtab %}
189+
{% endtabs %}
190+
191+
{% hint style="info" %}
192+
**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.
193+
{% endhint %}
194+
195+
Replace the following placeholders in the example:
196+
197+
| Placeholder | Description |
198+
|-------------|-------------|
199+
| `<XML_GLOB_PATH>` | Glob pattern matching your JUnit XML test report files (for example, `**/junit.xml`) |
200+
| `<TRUNK_ORG_SLUG>` | Your Trunk organization slug |
201+
| `<YOUR_SECRET_NAME>` | The name of the secret you created in GCP Secret Manager |
202+
203+
See the [uploader.md](../../uploader.md "mention") for all available command line arguments and usage.
204+
205+
#### Stale files
206+
207+
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.
208+
209+
{% hint style="success" %}
210+
**Have questions?**
211+
212+
Join us and 1500+ fellow engineers [on Slack](https://slack.trunk.io/) to get help with Trunk.
213+
{% endhint %}

summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
* [CircleCI](flaky-tests/get-started/ci-providers/circleci.md)
8686
* [Drone CI](flaky-tests/get-started/ci-providers/droneci.md)
8787
* [GitHub Actions](flaky-tests/get-started/ci-providers/github-actions.md)
88+
* [Google Cloud Build](flaky-tests/get-started/ci-providers/google-cloud-build.md)
8889
* [GitLab](flaky-tests/get-started/ci-providers/gitlab.md)
8990
* [Jenkins](flaky-tests/get-started/ci-providers/jenkins.md)
9091
* [Semaphore CI](flaky-tests/get-started/ci-providers/semaphoreci.md)

0 commit comments

Comments
 (0)