0

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?

0

2 Answers 2

2

As suggested in this stackoverflow Thread

  • Replace the current Cloud SDK builder image you are using with the "cloud builder CloudSDK" in your Cloud Build configuration.

  • Remove gcloud in your args list because it's the default entry point of your cloud builder container. you can directly specify the arguments for the gcloud command without including gcloud as a separate argument.

 - name: 'gcr.io/cloud-builders/gcloud'
 args:
   - 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}
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Sathi. I'm sorry for such a late reply. I figured out the solution and couldn't update it here. Basically, the issue was due to the lack of entrypoint being mentioned. And a bit of a change in formatting. I am adding the updated answer below.
0

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}

1 Comment

For future readers, both answers are similar. I recommend the solution by @Sathi because of the better choice of cloud builders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.