cr_buildtrigger_pubsub {googleCloudRunner} | R Documentation |
Create a buildtrigger pub/sub object
Description
Create a trigger from a Pub/Sub topic
Usage
cr_buildtrigger_pubsub(
topic,
serviceAccountEmail = NULL,
projectId = cr_project_get()
)
Arguments
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 |
Details
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.
See Also
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()
Examples
# 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)
[Package googleCloudRunner version 0.5.0 Index]