Hi Everyone.
I am dealing with an issue with Cloud Build failing to deploy a gen2 cloud function.
The build is triggered every time I push to a repository on GitHub.
Here is a snippet that I have in my cloud build file (the part which 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}
However, with this, the build fails citing the following:
ERROR: (gcloud.functions.deploy) ResponseError: status=[400], code=[Ok], message=[Trigger event type must be specified.]
However, the same CLI command works and deploys the gen2 cloud function when run in the terminal.
What am I doing wrong here?
Solved! Go to Solution.
Hi @anjelisa !
Thank you for your reply.
I figured out a solution to the above problem.
Earlier, I could deploy the gen2 cloud functions using the same CLI command but it wasn't working in the cloud build file. The issue was with the way I was trying to execute it. The entrypoint needs to be specified. This happens only for gen2 cloud functions, and not for gen1 functions.
Here is an updated step to be included in the cloud build file that works perfectly fine.
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: 'bash'
args:
- "-c"
- |
gcloud functions deploy function_name \
--gen2 \
--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=${_FIRESTORE_TRIGGER_REGION} \
--trigger-service-account='${_TRIGGER_SERVICE_ACCOUNT}' \
--runtime python39 \
--entry-point main \
--region=${_FIRESTORE_CF_REGION} \
--source=./Source/Directory \
--set-env-vars var1=${_TRIGGER_VAR_1},db_url=${_URL}