CloudBuildTrigger

Property Value
Google Cloud Service Name Cloud Build
Google Cloud Service Documentation /cloud-build/docs/
Google Cloud REST Resource Name v1.projects.triggers
Google Cloud REST Resource Documentation /cloud-build/docs/reference/rest/v1/projects.triggers
Config Connector Resource Short Names gcpcloudbuildtrigger
gcpcloudbuildtriggers
cloudbuildtrigger
Config Connector Service Name cloudbuild.googleapis.com
Config Connector Resource Fully Qualified Name cloudbuildtriggers.cloudbuild.cnrm.cloud.google.com
Can Be Referenced by IAMPolicy/IAMPolicyMember No

Custom Resource Definition Properties

Annotations

Fields
cnrm.cloud.google.com/project-id

Spec

Schema

build:
  images:
  - string
  step:
  - args:
    - string
    dir: string
    entrypoint: string
    env:
    - string
    id: string
    name: string
    secretEnv:
    - string
    timeout: string
    timing: string
    volumes:
    - name: string
      path: string
    waitFor:
    - string
  tags:
  - string
  timeout: string
description: string
disabled: boolean
filename: string
github:
  name: string
  owner: string
  pullRequest:
    branch: string
    commentControl: string
  push:
    branch: string
    tag: string
ignoredFiles:
- string
includedFiles:
- string
substitutions:
  string: string
triggerTemplate:
  branchName: string
  commitSha: string
  dir: string
  repoRef:
    external: string
    name: string
    namespace: string
  tagName: string
Fields

build

Optional

object

Contents of the build template. Either a filename or build template must be provided.

build.images

Optional

list (string)

build.images.[]

Optional

string

build.step

Required*

list (object)

build.step.[]

Required*

object

build.step.[].args

Optional

list (string)

build.step.[].args.[]

Optional

string

build.step.[].dir

Optional

string

Working directory to use when running this step's container. If this value is a relative path, it is relative to the build's working directory. If this value is absolute, it may be outside the build's working directory, in which case the contents of the path may not be persisted across build step executions, unless a 'volume' for that path is specified. If the build specifies a 'RepoSource' with 'dir' and a step with a 'dir', which specifies an absolute path, the 'RepoSource' 'dir' is ignored for the step's execution.

build.step.[].entrypoint

Optional

string

Entrypoint to be used instead of the build step image's default entrypoint. If unset, the image's default entrypoint is used

build.step.[].env

Optional

list (string)

build.step.[].env.[]

Optional

string

build.step.[].id

Optional

string

Unique identifier for this build step, used in 'wait_for' to reference this build step as a dependency.

build.step.[].name

Required*

string

The name of the container image that will run this particular build step. If the image is available in the host's Docker daemon's cache, it will be run directly. If not, the host will attempt to pull the image first, using the builder service account's credentials if necessary. The Docker daemon's cache will already have the latest versions of all of the officially supported build steps (https://github.com/GoogleCloudPlatform/cloud-builders). The Docker daemon will also have cached many of the layers for some popular images, like "ubuntu", "debian", but they will be refreshed at the time you attempt to use them. If you built an image in a previous build step, it will be stored in the host's Docker daemon's cache and is available to use as the name for a later build step.

build.step.[].secretEnv

Optional

list (string)

build.step.[].secretEnv.[]

Optional

string

build.step.[].timeout

Optional

string

Time limit for executing this build step. If not defined, the step has no time limit and will be allowed to continue to run until either it completes or the build itself times out.

build.step.[].timing

Optional

string

Output only. Stores timing information for executing this build step.

build.step.[].volumes

Optional

list (object)

build.step.[].volumes.[]

Optional

object

build.step.[].volumes.[].name

Required*

string

Name of the volume to mount. Volume names must be unique per build step and must be valid names for Docker volumes. Each named volume must be used by at least two build steps.

build.step.[].volumes.[].path

Required*

string

Path at which to mount the volume. Paths must be absolute and cannot conflict with other volume paths on the same build step or with certain reserved volume paths.

build.step.[].waitFor

Optional

list (string)

build.step.[].waitFor.[]

Optional

string

build.tags

Optional

list (string)

build.tags.[]

Optional

string

build.timeout

Optional

string

Amount of time that this build should be allowed to run, to second granularity. If this amount of time elapses, work on the build will cease and the build status will be TIMEOUT. This timeout must be equal to or greater than the sum of the timeouts for build steps within the build. The expected format is the number of seconds followed by s. Default time is ten minutes (600s).

description

Optional

string

Human-readable description of the trigger.

disabled

Optional

boolean

Whether the trigger is disabled or not. If true, the trigger will never result in a build.

filename

Optional

string

Path, from the source root, to a file whose contents is used for the template. Either a filename or build template must be provided.

github

Optional

object

Describes the configuration of a trigger that creates a build whenever a GitHub event is received. One of 'trigger_template' or 'github' must be provided.

github.name

Optional

string

Name of the repository. For example: The name for https://github.com/googlecloudplatform/cloud-builders is "cloud-builders".

github.owner

Optional

string

Owner of the repository. For example: The owner for https://github.com/googlecloudplatform/cloud-builders is "googlecloudplatform".

github.pullRequest

Optional

object

filter to match changes in pull requests. Specify only one of pullRequest or push.

github.pullRequest.branch

Required*

string

Regex of branches to match.

github.pullRequest.commentControl

Optional

string

Whether to block builds on a "/gcbrun" comment from a repository owner or collaborator. Possible values: ["COMMENTS_DISABLED", "COMMENTS_ENABLED"]

github.push

Optional

object

filter to match changes in refs, like branches or tags. Specify only one of pullRequest or push.

github.push.branch

Optional

string

Regex of branches to match. Specify only one of branch or tag.

github.push.tag

Optional

string

Regex of tags to match. Specify only one of branch or tag.

ignoredFiles

Optional

list (string)

ignoredFiles.[]

Optional

string

includedFiles

Optional

list (string)

includedFiles.[]

Optional

string

substitutions

Optional

map (key: string, value: string)

Substitutions data for Build resource.

triggerTemplate

Optional

object

Template describing the types of source changes to trigger a build. Branch and tag names in trigger templates are interpreted as regular expressions. Any branch or tag change that matches that regular expression will trigger a build. One of 'trigger_template' or 'github' must be provided.

triggerTemplate.branchName

Optional

string

Name of the branch to build. Exactly one a of branch name, tag, or commit SHA must be provided. This field is a regular expression.

triggerTemplate.commitSha

Optional

string

Explicit commit SHA to build. Exactly one of a branch name, tag, or commit SHA must be provided.

triggerTemplate.dir

Optional

string

Directory, relative to the source root, in which to run the build. This must be a relative path. If a step's dir is specified and is an absolute path, this value is ignored for that step's execution.

triggerTemplate.repoRef

Optional

object

The Cloud Source Repository to build. If omitted, the repo with name "default" is assumed.

triggerTemplate.repoRef.external

Optional

string

The name of a SourceRepoRepository.

triggerTemplate.repoRef.name

Optional

string

Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

triggerTemplate.repoRef.namespace

Optional

string

Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/

triggerTemplate.tagName

Optional

string

Name of the tag to build. Exactly one of a branch name, tag, or commit SHA must be provided. This field is a regular expression.

* Field is required when parent field is specified

Status

Schema

conditions:
- lastTransitionTime: string
  message: string
  reason: string
  status: string
  type: string
createTime: string
triggerId: string
Fields
conditions

list (object)

conditions.[]

object

conditions.[].lastTransitionTime

string

Last time the condition transitioned from one status to another.

conditions.[].message

string

Human-readable message indicating details about last transition.

conditions.[].reason

string

Unique, one-word, CamelCase reason for the condition's last transition.

conditions.[].status

string

Status is the status of the condition. Can be True, False, Unknown.

conditions.[].type

string

Type is the type of the condition.

createTime

string

Time when the trigger was created.

triggerId

string

The unique identifier for the trigger.

Sample YAML(s)

Build Trigger For Cloud Source Repo

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: cloudbuild.cnrm.cloud.google.com/v1beta1
kind: CloudBuildTrigger
metadata:
  name: cloudbuildtrigger-sample-cloudsourcerepo
spec:
  description: Cloud Build Trigger for building the master branch of the referenced Cloud Source Repository.
  disabled: false
  triggerTemplate:
    repoRef:
      name: cloudbuildtrigger-dep-cloudsourcerepo
    dir: "team-a/service-b"
    branchName: master
  ignoredFiles:
    - "**/*.md"
  includedFiles:
    - "src/**"
  substitutions:
    "_SERVICE_NAME": "service-name"
  build:
    # Note: $PROJECT_ID and $COMMIT_SHA are variables that are expanded by the
    # Cloud Build API when the build is created. More info:
    # https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values
    images: ["gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA"]
    tags: ["team-a", "service-b"]
    timeout: 1800s
    step:
      - id: "download_zip"
        name: gcr.io/cloud-builders/gsutil
        args: ["cp", "gs://mybucket/remotefile.zip", "localfile.zip"]
        timeout: 300s
      - id: "build_package"
        name: gcr.io/cloud-builders/go
        args: ["build", "my_package"]
        dir: directory
        env:
          - "ENV1=one"
          - "ENV2=two"
        secretEnv:
          - "SECRET_ENV1"
        timeout: 300s
      - id: "build_docker_image"
        name: gcr.io/cloud-builders/docker
        args: ["build", "-t", "gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA", "-f", "Dockerfile", "."]
        timeout: 300s
---
apiVersion: sourcerepo.cnrm.cloud.google.com/v1beta1
kind: SourceRepoRepository
metadata:
  name: cloudbuildtrigger-dep-cloudsourcerepo

Build Trigger For GitHub Repo

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: cloudbuild.cnrm.cloud.google.com/v1beta1
kind: CloudBuildTrigger
metadata:
  name: cloudbuildtrigger-sample-github
spec:
  # Cloud Build Triggers for GitHub repositories require that you first connect
  # your GCP project to your GitHub repository. More info:
  # https://cloud.google.com/cloud-build/docs/automating-builds/create-github-app-triggers
  description: Cloud Build Trigger for building the master branch of the GitHub repository at github.com/owner_name/repo_name
  disabled: false
  github:
    owner: owner_name
    name: repo_name
    push:
      branch: master
  ignoredFiles:
    - "**/*.md"
  includedFiles:
    - "src/**"
  substitutions:
    "_SERVICE_NAME": "service-name"
  build:
    # Note: $PROJECT_ID and $COMMIT_SHA are variables that are expanded by the
    # Cloud Build API when the build is created. More info:
    # https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values
    images: ["gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA"]
    tags: ["team-a", "service-b"]
    timeout: 1800s
    step:
      - id: "download_zip"
        name: gcr.io/cloud-builders/gsutil
        args: ["cp", "gs://mybucket/remotefile.zip", "localfile.zip"]
        timeout: 300s
      - id: "build_package"
        name: gcr.io/cloud-builders/go
        args: ["build", "my_package"]
        dir: directory
        env:
          - "ENV1=one"
          - "ENV2=two"
        secretEnv:
          - "SECRET_ENV1"
        timeout: 300s
      - id: "build_docker_image"
        name: gcr.io/cloud-builders/docker
        args: ["build", "-t", "gcr.io/$PROJECT_ID/${_SERVICE_NAME}:$COMMIT_SHA", "-f", "Dockerfile", "."]
        timeout: 300s

Build Trigger With Template File

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: cloudbuild.cnrm.cloud.google.com/v1beta1
kind: CloudBuildTrigger
metadata:
  name: cloudbuildtrigger-sample-withtemplatefile
spec:
  description: Cloud Build Trigger with a build template file. Builds the master branch of the referenced Cloud Source Repository.
  disabled: false
  triggerTemplate:
    repoRef:
      name: cloudbuildtrigger-dep-withtemplatefile
    dir: "team-a/service-b"
    branchName: master
  ignoredFiles:
    - "**/*.md"
  includedFiles:
    - "src/**"
  substitutions:
    "_SERVICE_NAME": "service-name"
  filename: "cloudbuild.yaml"
---
apiVersion: sourcerepo.cnrm.cloud.google.com/v1beta1
kind: SourceRepoRepository
metadata:
  name: cloudbuildtrigger-dep-withtemplatefile