Search code examples
google-cloud-platformdeploymentgoogle-cloud-functionsyamlgoogle-cloud-build

Cloud Build failing to deploy gen2 cloud function in GCP


I am trying to deploy a gen2 cloud function via Cloud Build. The trigger is listening a push in a particular repository on github. The first couple of steps in the cloud build yaml file are executed perfectly but the function deployment fails.

Sharing the snippet of the cloudbuild.yaml file that fails:

- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
args:
  - gcloud
  - functions
  - deploy
  - function_name
  - --gen2
  - --entry-point=main
  - --runtime=python39
  - --region=${_CF_REGION}
  - --source=./sample/dir
  - --trigger-event-filters="type=google.cloud.firestore.document.v1.written"
  - --trigger-event-filters="database=(default)"
  - --trigger-event-filters-path-pattern="document=Sample/{docId}"
  - --trigger-location=${_TRIGGER_REGION}
  - --trigger-service-account=${_TRIGGER_SERVICE_ACCOUNT}

The error that I get in cloud build is:

ERROR: (gcloud.functions.deploy) ResponseError: status=[400], code=[Ok], message=[Trigger event type must be specified.]

The same CLI command works perfectly fine in the terminal. What am I doing wrong here?


Solution

  • Update: Figured out the solution. Here is what worked for me.

    - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
      entrypoint: 'bash'
      args:
       - "-c"
       - |
         gcloud functions deploy projects_changes \
         --gen2 \
         --trigger-event-filters='type=google.cloud.firestore.document.v1.written' \
         --trigger-event-filters='database=(default)' \
         --trigger-event-filters-path-pattern='document=Document/{docId}' \
         --trigger-location=${_ENV_VAR_FOR_REGION} \
         --trigger-service-account='${_TRIGGER_SERVICE_ACCOUNT}' \
         --runtime python39 \
         --entry-point main \
         --region=${_CF_REGION} \
         --source=./Source/Dir \
         --set-env-vars var_abc=${_VAR_ABC},var_xyz=${_VAR_XYZ}