View source: R/buildtriggers_events.R
cr_buildtrigger_pubsub | R Documentation |
Create a trigger from a Pub/Sub topic
cr_buildtrigger_pubsub( topic, serviceAccountEmail = NULL, projectId = cr_project_get() )
topic |
The name of the Cloud Pub/Sub topic or a Topic object from topics_get |
serviceAccountEmail |
Service account that will make the push request. |
projectId |
The GCP project the topic is created within |
When using a PubSub trigger, you can use data within your PubSub message in substitution variables within the build. The data from pubsub is available in the variable value: $(body.message.data.x)
when x is a field in the pubsub message.
Other BuildTrigger functions:
BuildTrigger()
,
GitHubEventsConfig()
,
cr_buildtrigger_copy()
,
cr_buildtrigger_delete()
,
cr_buildtrigger_edit()
,
cr_buildtrigger_get()
,
cr_buildtrigger_list()
,
cr_buildtrigger_repo()
,
cr_buildtrigger_run()
,
cr_buildtrigger_webhook()
,
cr_buildtrigger()
# create build object cloudbuild <- system.file("cloudbuild/cloudbuild_substitutions.yml", package = "googleCloudRunner" ) the_build <- cr_build_make(cloudbuild) # this build includes substitution variables that read from pubsub message var1 the_build # using googlePubSubR to create pub/sub topic if needed ## Not run: library(googlePubsubR) pubsub_auth() topics_create("test-topic") ## End(Not run) # create build trigger that will work from pub/subscription pubsub_trigger <- cr_buildtrigger_pubsub("test-topic") pubsub_trigger ## Not run: cr_buildtrigger(the_build, name = "pubsub-triggered-subs", trigger = pubsub_trigger) ## End(Not run) # make base64 encoded json for pubsub library(jsonlite) library(googlePubsubR) # the message with the var1 that will be passed into the Cloud Build via substitution message <- toJSON(list(var1 = "hello mum")) # turning into JSON and encoding send_me <- msg_encode(message) ## Not run: # send a PubSub message with the encoded data message topics_publish(PubsubMessage(send_me), "test-topic") # did it work? After a while should see logs if it did cr_buildtrigger_logs("pubsub-triggered-subs") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.