Converting gcloud command to CloudBuild.yaml for GCP Log Sink

496 Views Asked by At

I have created GCP Log Sinks using gcloud command and it works. I now want to move that code into a CloudBuild.Yaml file equivalent. Can someone please point me to the log sink cloud build yaml template please or if you can convert the below command to a cloudbuild.yaml file?

My gcloud command is below which works successfully from cloud shell:

gcloud logging sinks create test3-${_ENV} pubsub.googleapis.com/projects/amer-xxxxxx-us-yyyy-dv/topics/pppp-topic-qqq-pubsub-dv --log-filter='(resource.labels.job_name=("amer-xxx-dv-df-xhxh-sel-details") jsonPayload.message:("completed successfully") jsonPayload.step=("WriteSuccessfulRecords/BatchLoads/SinglePartitionWriteTables/ParMultiDo(WriteTables)")) OR (resource.labels.job_name=("amer-xxxx-dv-df-pqpq-sel-review") jsonPayload.message:("completed successfully") jsonPayload.step=("WriteSuccessfulRecords/BatchLoads/SinglePartitionWriteTables/ParMultiDo(WriteTables)")) OR (resource.labels.job_name=("amer-xxxx-dv-df-pqpq-order") jsonPayload.message:("completed successfully") jsonPayload.step=("WriteSuccessfulRecords/BatchLoads/SinglePartitionWriteTables/ParMultiDo(WriteTables)"))'
  

1

There are 1 best solutions below

0
On

What's the difficulty?

- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
    - -c
    - |
        gcloud logging sinks create test3-${_ENV} pubsub.googleapis.com/projects/amer-xxxxxx-us-yyyy-dv/topics/pppp-topic-qqq-pubsub-dv --log-filter='(resource.labels.job_name=("amer-xxx-dv-df-xhxh-sel-details") jsonPayload.message:("completed successfully") jsonPayload.step=("WriteSuccessfulRecords/BatchLoads/SinglePartitionWriteTables/ParMultiDo(WriteTables)")) OR (resource.labels.job_name=("amer-xxxx-dv-df-pqpq-sel-review") jsonPayload.message:("completed successfully") jsonPayload.step=("WriteSuccessfulRecords/BatchLoads/SinglePartitionWriteTables/ParMultiDo(WriteTables)")) OR (resource.labels.job_name=("amer-xxxx-dv-df-pqpq-order") jsonPayload.message:("completed successfully") jsonPayload.step=("WriteSuccessfulRecords/BatchLoads/SinglePartitionWriteTables/ParMultiDo(WriteTables)"))'
  

And set correctly your _ENV substitution variable when you invoke your Cloud Build