Installation
Install as Agent Plugin
Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install cloud-build-basics@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin cloud-build-basics v1.0.0 follows the Agent Plugins spec.
Install with the gh extension
gh skills-hub install cloud-build-basics Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/cloud-build-basics/ Extract the ZIP to .github/skills/ in your repo. The folder name must match cloud-build-basics for Copilot to auto-discover it.
Skill Files (5)
SKILL.md 8.4 KB
---
name: cloud-build-basics
metadata:
version: "1.0.3"
category: DevOps
description: >-
Teaches the fundamentals of Cloud Build on Google Cloud. Covers core concepts,
API enablement, console navigation to the Build History page, and the end-to-end
workflow for creating and manually running a basic build trigger. Do not use for
managing private pools or complex pipeline architectures.
---
# Cloud Build Basics
## Attribution
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
MUST read [Usage Attribution](references/attribution.md). For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix `gcloud` with
`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-build-basics)"`
and append `agent-skills/1.0 (skill:cloud-build-basics)` to `User-Agent` headers.
## Prerequisites
Before starting, ensure the following prerequisites are met:
1. **Google Cloud SDK**: Ensure the [Google Cloud SDK](https://cloud.google.com/sdk/docs/install) is installed and configured.
2. **Authentication**: Authenticate the gcloud CLI:
```bash
gcloud auth login
gcloud auth application-default login
```
3. **Project ID**: Know the target Google Cloud Project ID. Set the context:
```bash
gcloud config set project <PROJECT_ID>
```
4. **Enable Cloud Build API**: The Cloud Build API must be enabled for the project.
```bash
gcloud services enable cloudbuild.googleapis.com
```
5. **Permissions**: Ensure the user or service account has the necessary permissions, such as `roles/cloudbuild.builds.editor` and `roles/serviceusage.serviceUsageAdmin` (to enable the API).
## Core Concepts
Cloud Build (GCB) is a serverless platform that executes your builds on Google Cloud. It translates your source code into deployable artifacts, such as Docker containers or Java archives.
| Concept | Description |
| :--- | :--- |
| **`cloudbuild.yaml`** | The required configuration file that defines the build steps. It is written in YAML or JSON. |
| **Build Steps** | A sequence of actions (steps) GCB performs. Each step runs a command inside a specific Docker container (the builder). Common builders include `gcr.io/cloud-builders/gcloud`, `gcr.io/cloud-builders/docker`, and custom containers. |
| **Artifacts** | The output of the build, typically a container image pushed to Google Container Registry (GCR) or Artifact Registry (AR), or other deployable files. |
| **Triggers** | Automation rules that invoke a build in response to an event, such as a push to a Git repository, a Pub/Sub message, or a manual request. |
## Navigation: Viewing Build History
The Cloud Build Build History page is the central place to monitor the status of past and ongoing builds.
1. **Open the Cloud Console**: Navigate to the Google Cloud Console.
2. **Go to Cloud Build**: Use the search bar or the navigation menu to find **Cloud Build**.
3. **Select Build History**: In the left navigation pane, select **History** (or use the direct URL: `https://console.cloud.google.com/cloud-build/builds`).
4. **Review Builds**:
* **Status**: Check the status column (`SUCCESS`, `FAILURE`, `WORKING`, `QUEUED`).
* **Region**: Use the region filter at the top to view builds that ran in a specific region (important for regional worker pools).
* **Logs**: Click on a specific Build ID to view the detailed logs, execution steps, and build summary. This is crucial for debugging failed builds.
> [!NOTE]
> If this is your first time visiting the page, you might see the "zero-state" experience, which offers options to run a sample build or create your first trigger (as noted in the [`cb-list-build-zero-state`](references/cb-list-build-zero-state.md) skill). Note that region settings for triggers and builds are immutable after creation and must be chosen deliberately.
## Creating a Basic Automated Trigger
This process defines an automation rule to run a build whenever code is pushed to a specified Git branch.
### Step 1: Start Trigger Creation
1. Navigate to the **Cloud Build Triggers** page (`https://console.cloud.google.com/cloud-build/triggers`).
2. Click **Create trigger**.
### Step 2: Configure Trigger Settings
1. **Name**: Provide a unique, descriptive name (e.g., `github-main-branch-build`).
2. **Region**: Select the region where the trigger configuration will be stored (e.g., `global` or a specific regional endpoint). **Note: Trigger and build region settings are immutable after creation and must be chosen deliberately.**
3. **Event**: Select the event type. For automated CI/CD, select **Push to a branch**.
4. **Source**: Select the repository source:
* **Repository**: Connect your source repository (GitHub, Bitbucket, Cloud Source Repositories, etc.). If needed, authorize the connection.
* **Repository Name**: Select the specific repository you want to link.
5. **Branch**: Enter the branch pattern (e.g., `^main$` or `^develop`).
### Step 3: Configure Build Settings
1. **Configuration**: Select **Cloud Build configuration file (yaml or json)**.
2. **Location**: Keep the default **Repository** and specify the path to your build configuration file (e.g., `cloudbuild.yaml`).
* *Alternative*: For very simple builds, you can choose **Inline** to paste the YAML configuration directly into the trigger.
3. **(Optional) Service Account**: For production environments, select a dedicated service account with limited permissions to enforce the principle of least privilege.
### Step 4: Save and Test
1. Click **Create**. The trigger is now active and will run automatically on the next matching Git push.
> [!TIP]
> The `cb-create-trigger` skill provides detailed `gcloud` commands for creating triggers across all types (GitHub, Pub/Sub, Webhook) and configurations (inline, Dockerfile, YAML). Use that skill for CLI automation.
## Running an Existing Trigger Manually
Sometimes you need to run a trigger on demand, outside of its normal automation flow (e.g., to rebuild an old commit or test a new substitution).
> [!IMPORTANT]
> **Substitution Immutability**: You can only override values for substitution variables that are **already defined in the trigger configuration**. You cannot introduce new substitution variable keys at runtime.
### Option A: Via the Cloud Console
1. Navigate to the **Cloud Build Triggers** page (`https://console.cloud.google.com/cloud-build/triggers`).
2. Locate the trigger you wish to run.
3. Click the vertical ellipsis (⋮) next to the trigger and select **Run**.
4. A dialog will appear, allowing you to specify:
* **Source branch/tag**: Choose the specific Git reference to build from.
* **Substitution Variables**: Override any existing substitution variables (e.g., set `_VERSION` to a new value).
5. Click **Run trigger**. The build will start immediately, and you can monitor its status on the **History** page.
### Option B: Via the gcloud CLI
Use the `gcloud builds triggers run` command to invoke the trigger and optionally override parameters.
```bash
# Run the trigger against the 'main' branch
gcloud builds triggers run <TRIGGER_NAME> \
--region=<REGION> \
--branch=main
# Run the trigger and override a substitution variable
gcloud builds triggers run <TRIGGER_NAME> \
--region=<REGION> \
--branch=main \
--substitutions=_IMAGE_TAG="20231027-manual"
# Monitor the initiated build
# Note: The run command outputs the build ID. Use it to check status:
# gcloud builds log <BUILD_ID> --region=<REGION>
```
> [!NOTE]
> The `cb-run-trigger` skill provides more complex invocation examples, including running against a specific commit SHA or using tags.
## Related Skills
* [`cb-create-trigger`](references/cb-create-trigger.md): Detailed CLI-focused instructions for creating all trigger types.
* [`cb-list-build-zero-state`](references/cb-list-build-zero-state.md): Advanced management of the Cloud Build dashboard and onboarding zero state.
* [`cb-run-trigger`](references/cb-run-trigger.md): Comprehensive guide to manually running triggers using various `gcloud` options.
## External Resources & Documentation
* [Cloud Build Documentation](https://cloud.google.com/build/docs)
* [Cloud Build Configuration File Schema](https://cloud.google.com/build/docs/build-config-file-schema)
* [Automating Builds with Triggers](https://cloud.google.com/build/docs/automating-builds/create-manage-triggers)
* [gcloud CLI builds Reference](https://cloud.google.com/sdk/gcloud/reference/builds)
references/
attribution.md 1.8 KB
# Usage Attribution
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command with
this skill, follow these usage attribution instructions. Tag every command you
execute directly in the terminal so usage can be attributed. The tag identifies
only the skill and its version; it carries no user data.
- **`gcloud` CLI Commands**: Prefix every `gcloud` invocation, whatever the
subcommand, with the metrics environment variable. Set it inline on each
command because shell state may not persist between commands:
```bash
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:cloud-build-basics)" \
gcloud <command> [flags]
```
Do not use `gcloud config set` for this: it would persist beyond the current
task and mislabel unrelated usage.
- **Direct HTTP, REST, and MCP Requests**: On direct HTTP calls to Google
Cloud APIs (for example with `curl`) or HTTP requests to a remote MCP
server, include `agent-skills/1.0 (skill:cloud-build-basics)` in the `User-Agent`
header. If a `User-Agent` header is already specified, append this string to
the end of it rather than overwriting existing `User-Agent` data — the
collection pipeline parses the `agent-skills/<version>` and `skill:<name>`
tokens, so any rewording breaks attribution:
```
User-Agent: <existing_user_agent> agent-skills/1.0 (skill:cloud-build-basics)
```
- **Constraint for Generated Code**: The tracking prefix is strictly for
commands you execute directly in the terminal. Do NOT include this tracking
prefix in generated scripts, Terraform templates, or code provided to the
user for their own repositories.
- **User Opt-Out**: If the user asks to disable or remove tracking or
attribution tags, omit the `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` variable
and custom `User-Agent` suffix from all commands.
cb-create-trigger.md 11.6 KB
---
name: cb-create-trigger
description: Creates a Cloud Build trigger to automate builds in response to repository events (pushes, tags, pull requests), Pub/Sub messages, Webhook events, or manual invocations. This skill covers all trigger types, repository services (GitHub, Cloud Source Repositories, Bitbucket, GitLab), and build configurations including YAML/JSON files, Dockerfiles, Buildpacks, and inline YAML.
---
## Table of Contents
- [Preconditions](#preconditions) (Lines 21-55)
- [Inputs](#inputs) (Lines 57-87)
- [Execution Steps](#execution-steps) (Lines 89-197)
- [Step 1: Authentication and Project Initialization](#step-1-authentication-and-project-initialization) (Lines 91-99)
- [Step 2: Enable Required APIs](#step-2-enable-required-apis) (Lines 101-107)
- [Step 3: Create the Trigger](#step-3-create-the-trigger) (Lines 109-182)
- [Step 4: Verification](#step-4-verification) (Lines 184-197)
- [Outputs](#outputs) (Lines 199-209)
- [Related Skills](#related-skills) (Lines 211-220)
## Preconditions
- **Authentication**: Run the following commands to ensure your CLI is
authenticated with the correct credentials:
```bash
gcloud auth login
gcloud auth application-default login
```
- **Project ID**: Ensure you have the `projectId`. If it is not already known,
prompt the user to provide the project ID where the trigger will be created.
- **Enable APIs**: Ensure the following APIs are enabled in your project:
- `cloudbuild.googleapis.com` (Cloud Build API)
- `secretmanager.googleapis.com` (Secret Manager API - required for
Webhook triggers)
- `pubsub.googleapis.com` (Cloud Pub/Sub API - required for Pub/Sub
triggers)
- **IAM Roles**: Ensure the user or service account has the following roles:
- `roles/cloudbuild.builds.editor` (Cloud Build Editor)
- `roles/iam.serviceAccountUser` (to use service accounts with the
trigger)
- `roles/pubsub.subscriber` (for the Cloud Build Service Agent if using
Pub/Sub triggers)
- `roles/secretmanager.admin` (if creating secrets for Webhook triggers)
- **Organization Policy**: Be aware that organization policies (e.g.,
`constraints/cloudbuild.allowedServiceAccounts` or
`constraints/gcp.resourceLocations`) may restrict service account selection
or regional availability.
## Inputs
Name | Type | Description | Required/Optional | Default
:----------------------- | :------ | :------------------------------------------------------------------------------------------------------------ | :----------------------------------- | :------
`name` | String | A unique name for the trigger within the project's region. Must be alphanumeric and hyphens only. | Required | -
`region` | String | The region where the trigger will be stored. **Warning: Immutable after creation.** | Required | `global`
`description` | String | A concise explanation of the trigger's purpose. | Optional | -
`tags` | List | Arbitrary strings used to organize and filter triggers. | Optional | -
`event_type` | Enum | The event that invokes the trigger: `push_branch`, `push_tag`, `pull_request`, `manual`, `pubsub`, `webhook`. | Required | `push_branch`
`repo_service` | Enum | The repository service: `github`, `cloud_source_repositories`, `bitbucket`, `gitlab`, `developer_connect`. | Required | `github`
`repo_generation` | Enum | `1st_gen` or `2nd_gen`. Note: 2nd-gen is not available in the `global` region. | Required | `1st_gen`
`repository` | String | Name or resource path of the connected repository. | Required | -
`branch_pattern` | String | Regular expression to match branches (e.g., `^main$`). | Required for branch events | -
`tag_pattern` | String | Regular expression to match tags (e.g., `^v.*`). | Required for tag events | -
`pull_request_pattern` | String | Regular expression to match the base branch for pull requests. | Required for PR events | -
`config_type` | Enum | `yaml_json` (Standard), `dockerfile`, `buildpacks`. | Required | `yaml_json`
`config_source` | Enum | `repository` (File in repo) or `inline` (YAML provided directly). | Required | `repository`
`config_file_path` | String | Path to the configuration file in the repository (e.g., `cloudbuild.yaml`). | Required for repo config | `cloudbuild.yaml`
`inline_config_path` | String | Local path to a YAML/JSON file containing the build configuration to be embedded. | Required for inline config | -
`dockerfile` | String | Path to the Dockerfile in the repository. | Required for Docker builds | `Dockerfile`
`dockerfile_dir` | String | Directory context for the Docker build. | Optional | `/`
`dockerfile_image` | String | Destination container image tag. | Optional | -
`service_account` | String | The service account used for build execution. Strongly recommended for security. | Optional (may be required by policy) | -
`substitution_variables` | Map | Key-value pairs for build parameterization (e.g., `_DEPLOY_ENV=prod`). | Optional | -
`require_approval` | Boolean | Whether builds require manual approval before execution. | Optional | `false`
`pubsub_topic` | String | The Pub/Sub topic to subscribe to. | Required for Pub/Sub events | -
`webhook_secret` | String | Secret Manager secret version path (e.g., `projects/.../secrets/.../versions/...`). | Required for Webhook events | -
`ignored_files` | List | Glob patterns for files that should not trigger builds. | Optional | -
`included_files` | List | Glob patterns for files that MUST be changed to trigger builds. | Optional | -
`cel_filter` | String | Common Expression Language (CEL) filter for Pub/Sub or Webhook events. | Optional | -
## Execution steps
### Step 1: Authentication and Project Initialization
Ensure the environment is configured correctly.
```bash
gcloud auth login
gcloud auth application-default login
gcloud config set project <PROJECT_ID>
```
### Step 2: Enable Required APIs
Enable services based on the chosen trigger type.
```bash
gcloud services enable cloudbuild.googleapis.com secretmanager.googleapis.com pubsub.googleapis.com
```
### Step 3: Create the Trigger
Choose the subcommand based on the `repo_service` and `event_type`.
**Option A: Create a GitHub Trigger (1st gen)** Use this for standard continuous
deployment from a GitHub repository.
```bash
gcloud builds triggers create github \
--name=<NAME> \
--region=<REGION> \
--repo-owner=<REPO_OWNER> \
--repo-name=<REPO_NAME> \
--branch-pattern="<BRANCH_REGEX>" \
--build-config="<CONFIG_FILE_PATH>" \
--service-account="projects/<PROJECT_ID>/serviceAccounts/<SERVICE_ACCOUNT_EMAIL>" \
--substitutions="_KEY=VALUE" \
--ignored-files="docs/**,README.md"
```
**Option B: Create a Manual Trigger** Use this for triggers that are only
invoked on-demand or on a schedule.
```bash
gcloud builds triggers create manual \
--name=<NAME> \
--region=<REGION> \
--repo="https://github.com/<OWNER>/<REPO>" \
--repo-type=GITHUB \
--branch="<BRANCH>" \
--build-config="<CONFIG_FILE_PATH>"
```
**Option C: Create a Webhook Trigger** Use this to trigger builds via external
HTTP POST requests. Requires a secret in Secret Manager.
```bash
gcloud builds triggers create webhook \
--name=<NAME> \
--region=<REGION> \
--secret="projects/<PROJECT_ID>/secrets/<SECRET_NAME>/versions/<VERSION>" \
--branch="<BRANCH>" \
--repo="https://github.com/<OWNER>/<REPO>" \
--repo-type=GITHUB \
--build-config="<CONFIG_FILE_PATH>"
```
**Option D: Create a Pub/Sub Trigger** Use this to trigger builds in response to
messages published to a topic.
```bash
gcloud builds triggers create pubsub \
--name=<NAME> \
--region=<REGION> \
--topic="projects/<PROJECT_ID>/topics/<TOPIC_NAME>" \
--branch="<BRANCH>" \
--repo="https://github.com/<OWNER>/<REPO>" \
--repo-type=GITHUB \
--build-config="<CONFIG_FILE_PATH>"
```
**Option E: Create a Trigger with Inline Configuration** Use this to embed the
build steps directly within the trigger instead of a file in the repository.
```bash
gcloud builds triggers create github \
--name=<NAME> \
--region=<REGION> \
--repo-owner=<REPO_OWNER> \
--repo-name=<REPO_NAME> \
--branch-pattern="<BRANCH_REGEX>" \
--inline-config="<LOCAL_PATH_TO_YAML>"
```
### Step 4: Verification
Confirm the trigger has been created and is enabled.
```bash
gcloud builds triggers describe <NAME> --region=<REGION>
```
To list all triggers in a region:
```bash
gcloud builds triggers list --region=<REGION>
```
## Outputs
| Name | Description |
| :------------- | :--------------------------------------------------------- |
| `trigger_name` | The unique name of the created trigger. |
| `trigger_id` | The system-generated UUID for the trigger. |
| `webhook_url` | The URL used to invoke a Webhook trigger (includes the key |
: : and secret placeholders). :
| `topic_name` | The Pub/Sub topic associated with the trigger (if |
: : applicable). :
| `region` | The location where the trigger resource resides. |
## Related skills
- [`cb-run-trigger`](./cb-run-trigger.md): Manually invoke an existing trigger with revision
overrides.
- `secret-manager-create-secret`: Create and manage secrets for Webhook
authentication.
- `pubsub-create-topic`: Create topics for Pub/Sub triggers or build
notifications.
- `cloud-build-create-worker-pool`: Create private worker pools for regional
builds. cb-list-build-zero-state.md 7.2 KB
---
name: cb-list-build-zero-state
description: Manages the Cloud Build zero-state experience, including running sample builds, creating triggers, and navigating regional or jurisdictional limitations like DRZ.
---
## Table of Contents
- [Preconditions](#preconditions) (Lines 22-37)
- [Inputs](#inputs) (Lines 39-55)
- [Execution Steps](#execution-steps) (Lines 57-163)
- [Step 1: Authentication and Project Selection](#step-1-authentication-and-project-selection) (Lines 59-67)
- [Step 2: Verify Project Zero State](#step-2-verify-project-zero-state) (Lines 69-82)
- [Step 3: Option A: Run Sample Build (Manual)](#step-3-actionable-onboarding---option-a-run-sample-build-manual) (Lines 84-96)
- [Step 4: Option B: Create Trigger (Continuous Deployment)](#step-4-actionable-onboarding---option-b-create-trigger-continuous-deployment) (Lines 98-112)
- [Step 5: Option C: Inline Configuration](#step-5-actionable-onboarding---option-c-inline-configuration) (Lines 114-126)
- [Step 6: Advanced Settings and Constraints](#step-6-advanced-settings-and-constraints) (Lines 128-151)
- [Step 7: Monitoring Build Execution](#step-7-monitoring-build-execution) (Lines 153-163)
- [Outputs](#outputs) (Lines 165-174)
- [Related Skills](#related-skills) (Lines 176-181)
## Preconditions
- **Authentication**: Run the following commands to authenticate:
- `gcloud auth login`
- `gcloud auth application-default login`
- **Project ID**: Prompt the user for the `projectId` if it is not already
known.
- **Enabled APIs**: Ensure the Cloud Build API is enabled:
- `cloudbuild.googleapis.com`
- **Permissions**: Ensure you have the following IAM permissions:
- `cloudbuild.builds.list`
- `cloudbuild.builds.get`
- `cloudbuild.builds.create`
- `roles/cloudbuild.builds.editor` (Recommended)
## Inputs
Name | Type | Description | Required/Optional | Default
:--------------- | :----- | :---------------------------------------------------------------------------------------------------------------------- | :---------------- | :------
`projectId` | String | The ID of the GCP project. | Required | -
`region` | String | Regional location for builds/triggers (e.g., `us-central1`). **Note: Region cannot be changed after trigger creation.** | Optional | `global`
`triggerName` | String | Name for the new build trigger. | Optional | -
`repoOwner` | String | Owner of the GitHub/Bitbucket repository (e.g., `GoogleCloudBuild`). | Optional | -
`repoName` | String | Name of the repository (e.g., `cloud-console-sample-build`). | Optional | -
`branchPattern` | String | Regex for branches to trigger on (e.g., `^main$`). | Optional | `^main$`
`substitutions` | Map | Key-value pairs for build substitutions (e.g., `_KEY=VALUE`). | Optional | -
`serviceAccount` | String | Service account email to execute builds. | Optional | Default GCB SA
> [!IMPORTANT] **Sample builds** are not supported in Jurisdictional (DRZ) or
> BYOID environments. **1st-gen repository connections** are disabled in DRZ
> regions (US, EU, Saudi Arabia).
## Execution steps
### Step 1: Authentication and Project Selection
Authenticate and set the project context for all subsequent commands.
```bash
gcloud auth login
gcloud auth application-default login
gcloud config set project <PROJECT_ID>
```
### Step 2: Verify Project Zero State
Confirm that no builds or triggers currently exist in the target region.
```bash
# List recent builds to verify empty state
gcloud builds list --region=<REGION> --limit=5
# List existing triggers
gcloud builds triggers list --region=<REGION>
```
Validation: If the project is in a zero state, these commands should return no
results or an empty list.
> [!IMPORTANT]
> **Region Immutability**: Region settings for triggers and builds are immutable after creation and must be chosen deliberately during zero-state initialization.
### Step 3: Actionable Onboarding - Option A: Run Sample Build (Manual)
Use this step to try Cloud Build with sample code. This mimics the "Run sample
build" CTA in the console.
```bash
# Clone the sample repository
git clone https://github.com/GoogleCloudBuild/cloud-console-sample-build && \
cd cloud-console-sample-build
# Submit the build to Cloud Build
gcloud builds submit --config cloudbuild.yaml --region=<REGION>
```
### Step 4: Actionable Onboarding - Option B: Create Trigger (Continuous Deployment)
Create a trigger to automatically start builds on code changes.
```bash
gcloud builds triggers create github \
--name=<TRIGGER_NAME> \
--repo-name=<REPO_NAME> \
--repo-owner=<REPO_OWNER> \
--branch-pattern=<BRANCH_PATTERN> \
--build-config="cloudbuild.yaml" \
--region=<REGION> \
--require-approval
```
### Step 5: Actionable Onboarding - Option C: Inline Configuration
Create a trigger using an inline build configuration instead of a file in the
repository.
```bash
gcloud builds triggers create github \
--name=<TRIGGER_NAME> \
--repo-name=<REPO_NAME> \
--repo-owner=<REPO_OWNER> \
--branch-pattern=<BRANCH_PATTERN> \
--inline-config="local-config.yaml" \
--region=<REGION>
```
### Step 6: Advanced Settings and Constraints
Apply specific configurations for security, networking, or identity.
**Identity and Substitutions**
```bash
# Update trigger with a specific service account and substitutions
gcloud builds triggers update github <TRIGGER_NAME> \
--service-account="projects/<PROJECT_ID>/serviceAccounts/<SA_EMAIL>" \
--update-substitutions="_VERSION=v1,_ENV=prod" \
--region=<REGION>
```
**Handling Regional Outages**
If a region is unreachable (e.g., `us-east4`), you will see a warning. You can
still list builds from other locations.
```bash
# Check status of unreachable locations
gcloud builds list --region=global
```
### Step 7: Monitoring Build Execution
After triggering or submitting a build, monitor its progress.
```bash
# List builds with the sample tag
gcloud builds list --filter='tags="gcp-cloud-build-sample-build"' --region=<REGION>
# View logs for a specific build
gcloud builds log <BUILD_ID> --region=<REGION>
```
## Outputs
Name | Type | Description
:---------- | :----- | :----------------------------------------------------
`buildId` | String | The unique identifier of the executed build.
`triggerId` | String | The unique identifier of the created trigger.
`status` | String | Final status of the build (e.g., SUCCESS, FAILURE).
`imageUri` | String | The URI of the built container image (if applicable).
## Related skills
- `cb-connect-repo`
- [`cb-run-trigger`](./cb-run-trigger.md)
- `artifact-registry-manage-images` cb-run-trigger.md 5.9 KB
---
name: cb-run-trigger
description: Manually executes a predefined Cloud Build trigger to start a build. Supports specifying a Git branch, tag, or commit SHA for source-based triggers, and overriding substitution variables for all trigger types.
---
## Table of Contents
- [Preconditions](#preconditions) (Lines 19-38)
- [Inputs](#inputs) (Lines 40-62)
- [Execution Steps](#execution-steps) (Lines 64-132)
- [Step 1: Set Project Context](#step-1-set-the-project-context) (Lines 66-72)
- [Step 2: Run the Cloud Build Trigger](#step-2-run-the-cloud-build-trigger) (Lines 74-114)
- [Step 3: Verify Build Initiation and Monitor Status](#step-3-verify-build-initiation-and-monitor-status) (Lines 116-132)
- [Outputs](#outputs) (Lines 134-143)
- [Related Skills](#related-skills) (Lines 145-151)
## Preconditions
* The Cloud Build API (`cloudbuild.googleapis.com`) must be enabled in the
project.
* The user must have the `roles/cloudbuild.builds.editor` IAM role to initiate
builds.
* If the trigger is configured with a user-managed service account, the user
must also have the `roles/iam.serviceAccountUser` permission on that service
account (`iam.serviceAccounts.actAs`).
* Authenticate the `gcloud` CLI:
```bash
gcloud auth login
gcloud auth application-default login
```
* Identify the target Google Cloud Project ID. If not known, prompt the user
for it.
## Inputs
Name | Type | Description | Required/Optional | Default
:-------------- | :----- | :------------------------------------------------------------------------------------------------------------ | :---------------- | :------
`projectId` | String | The ID of the Google Cloud project where the trigger resides. | Required | -
`triggerId` | String | The unique name or UUID of the trigger to execute. | Required | -
`region` | String | The region where the trigger is defined (e.g., `global`, `us-central1`). | Required | `global`
`revisionType` | String | The type of source revision to build: `branch`, `tag`, or `sha`. Not applicable for repoless/inline triggers. | Optional | `branch`
`revisionValue` | String | The actual value for the revision (e.g., branch name `main`, tag `v1.2.0`, or commit hash `7a1b3c4`). | Optional | -
`substitutions` | Map | Key-value pairs for substitution variable overrides (e.g., `_ENVIRONMENT=prod,_TAG=latest`). | Optional | -
> [!IMPORTANT] **Pricing**: Trigger invocation is free ($0.00). However, the
> resulting build consumes compute resources. Cloud Build provides 120 free
> build-minutes per day on default machine types. Beyond this, standard
> per-minute rates apply based on the machine type and region.
> [!WARNING] **Substitution Immutability**: You can only override values for
> substitution variables that are ALREADY defined in the trigger configuration.
> You cannot add new keys at runtime.
> [!NOTE] **Jurisdictional Constraints**: In Jurisdictional Consoles (DRZ),
> triggers using legacy 1st-gen repositories are disabled for manual runs. Only
> 2nd-gen repositories are supported.
## Execution steps
### Step 1: Set the project context
Ensure the `gcloud` CLI is pointing to the correct project.
```bash
gcloud config set project <PROJECT_ID>
```
### Step 2: Run the Cloud Build trigger
Choose the appropriate variation based on the trigger configuration and desired
revision.
**Variation A: Run using a branch** Use this for triggers targeting a specific
Git branch.
```bash
gcloud builds triggers run <TRIGGER_ID> --region=<REGION> --branch=<BRANCH_NAME>
```
**Variation B: Run using a tag** Use this for triggers targeting a specific Git
tag.
```bash
gcloud builds triggers run <TRIGGER_ID> --region=<REGION> --tag=<TAG_NAME>
```
**Variation C: Run using a commit SHA** Use this to build a specific commit hash
(short or full 40-character hex SHA).
```bash
gcloud builds triggers run <TRIGGER_ID> --region=<REGION> --sha=<COMMIT_SHA>
```
**Variation D: Run with substitution overrides** Append the `--substitutions`
flag to any run command to override variables.
```bash
gcloud builds triggers run <TRIGGER_ID> --region=<REGION> --branch=<BRANCH_NAME> --substitutions="_VARIABLE_NAME=<VALUE>"
```
**Variation E: Run a repoless or inline trigger** For Manual, Pub/Sub, or
Webhook triggers that use an inline `cloudbuild.yaml` and no repository.
```bash
gcloud builds triggers run <TRIGGER_ID> --region=<REGION>
```
### Step 3: Verify build initiation and monitor status
The `run` command will output a build ID. Use this ID to check the status or
view the execution logs.
**Check build status:**
```bash
gcloud builds describe <BUILD_ID> --region=<REGION>
```
**Stream build logs:**
```bash
gcloud builds log <BUILD_ID> --region=<REGION>
```
## Outputs
| Name | Description |
| :------------ | :--------------------------------------------------------- |
| `buildId` | The unique identifier for the initiated build (e.g., |
: : `a1b2c3d4-e5f6-...`). :
| `buildStatus` | The current state of the build (e.g., `QUEUED`, `WORKING`, |
: : `SUCCESS`, `FAILURE`, `CANCELLED`). :
| `logUrl` | A link to view the live logs in the Google Cloud Console |
: : (derived from the build ID). :
## Related skills
* [`cb-create-trigger`](./cb-create-trigger.md): Create a new build trigger from a repository or inline
source.
* `cb-list-triggers`: List and filter all triggers in a project and region.
* `cb-approve-build`: Approve a pending build for triggers requiring manual
approval. License (Apache-2.0)
Apache-2.0
Source: google/skills
View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/google/skills/blob/main/LICENSE