Build Triggers are a way to have your builds respond to various events, most commonly a git commit or a pubsub event.

cr_buildtrigger(
  build,
  name,
  trigger,
  description = paste("cr_buildtrigger: ", Sys.time()),
  disabled = FALSE,
  substitutions = NULL,
  ignoredFiles = NULL,
  includedFiles = NULL,
  trigger_tags = NULL,
  projectId = cr_project_get(),
  sourceToBuild = NULL,
  overwrite = FALSE
)

Arguments

build

The build to trigger created via cr_build_make, or the file location of the cloudbuild.yaml within the trigger source

name

User assigned name of the trigger

trigger

The trigger source created via cr_buildtrigger_repo or a pubsub trigger made with cr_buildtrigger_pubsub or a webhook trigger made with cr_buildtrigger_webhook

description

Human-readable description of this trigger

disabled

If true, the trigger will never result in a build

substitutions

A named list of Build macro variables

ignoredFiles

ignored_files and included_files are file glob matches extended with support for "**".

includedFiles

If any of the files altered in the commit pass the ignored_files

trigger_tags

Tags for the buildtrigger listing

projectId

ID of the project for which to configure automatic builds

sourceToBuild

A cr_buildtrigger_repo object (but no regex allowed for branch or tag) This field is currently only used by Webhook, Pub/Sub, Manual, and Cron triggers and is the source of the build will execute upon.

overwrite

If TRUE will overwrite an existing trigger with the same name

Details

Any source specified in the build will be overwritten to use the trigger as a source (GitHub or Cloud Source Repositories)

If you want multiple triggers for a build, then duplicate the build and create another build under a different name but with a different trigger. Its easier to keep track of.

Examples

cr_project_set("my-project")
#>  2022-03-26 19:55:54 > ProjectId set to my-project
#> [1] "my-project"
cr_bucket_set("my-bucket")
#>  2022-03-26 19:55:54 > Bucket set to my-bucket
#> [1] "my-bucket"
cloudbuild <- system.file("cloudbuild/cloudbuild.yaml",
  package = "googleCloudRunner"
)
bb <- cr_build_make(cloudbuild)

# repo hosted on GitHub
gh_trigger <- cr_buildtrigger_repo("MarkEdmondson1234/googleCloudRunner")

# repo mirrored to Cloud Source Repositories
cs_trigger <- cr_buildtrigger_repo("github_markedmondson1234_googlecloudrunner",
  type = "cloud_source"
)
if (FALSE) {
# build with in-line build code
cr_buildtrigger(bb, name = "bt-github-inline", trigger = gh_trigger)

# build with in-line build code using Cloud Source Repository
cr_buildtrigger(bb, name = "bt-github-inline", trigger = cs_trigger)

# build pointing to cloudbuild.yaml within the GitHub repo
cr_buildtrigger("inst/cloudbuild/cloudbuild.yaml",
  name = "bt-github-file", trigger = gh_trigger
)

# build with repo mirror from file
cr_buildtrigger("inst/cloudbuild/cloudbuild.yaml",
  name = "bt-cs-file", trigger = cs_trigger
)
}

# creating build triggers that respond to pubsub events
if (FALSE) {
# create a pubsub topic either in webUI or via library(googlePubSubR)
library(googlePubsubR)
pubsub_auth()
topics_create("test-topic")
}

# create build trigger that will work from pub/subscription
pubsub_trigger <- cr_buildtrigger_pubsub("test-topic")
pubsub_trigger
#> ==CloudBuildTriggerPubSubConfig==
#> topic:  projects/my-project/topics/test-topic 
if (FALSE) {
# create the build trigger with in-line build
cr_buildtrigger(bb, name = "pubsub-triggered", trigger = pubsub_trigger)
# create scheduler that calls the pub/sub topic

cr_schedule("cloud-build-pubsub",
  "15 5 * * *",
  pubsubTarget = cr_schedule_pubsub("test-topic")
)
}

# create a pubsub trigger that uses github as a source of code to build upon
gh <- cr_buildtrigger_repo("MarkEdmondson1234/googleCloudRunner")
blist <- cr_build_make(cr_build_yaml(cr_buildstep_r('list.files()')))

if (FALSE) {
cr_buildtrigger(blist,
                name = "pubsub-triggered-github-source",
                trigger = pubsub_trigger,
                sourceToBuild = gh)
}