Cloud Build部署GCP Gen2 Cloud Function失败求助
Cloud Build部署Gen2 Cloud Function触发器失败的解决办法
问题核心:Cloud Build YAML的args数组中,给--trigger-event-filters等参数添加了双引号,导致gcloud命令无法正确识别触发器事件类型。本地终端执行时,shell会自动解析并去掉引号,但Cloud Build会把引号当作参数的一部分传递给gcloud,使得GCP无法识别带引号的事件类型值,因此抛出Trigger event type must be specified.错误。
修正后的cloudbuild.yaml代码片段:
- 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}
说明:Cloud Build的args数组每个元素会直接作为命令参数传递,无需额外给参数值添加引号。只有当参数包含空格、特殊字符时,才需要在YAML中用引号包裹整个参数元素(而非给参数值加引号),而你的这些参数值没有特殊字符,去掉引号即可让gcloud正确解析触发器配置。
内容的提问来源于stack exchange,提问作者Mursil
相关产品推荐
相关产品推荐

