尝试部署简单功能时,我遇到403错误。这是我的完整Yaml:
steps:
# Install Dependencies
- name: 'python'
id: Pip install
args: ['pip3', 'install', '-r', 'requirements.txt', '--user']
# Run Tests
- name: 'python'
args: ['python3', '-m', 'pytest', 'functions/folder_a/test/']
# Deploy Cloud Functions
- name: 'gcr.io/cloud-builders/gcloud'
id: 'helloFunction'
args: ['functions', 'deploy', 'hello', '--source' , 'functions/folder_a/main.py',
'--runtime' , 'python37' ,'--trigger-http']
第一步很好完成,但第二步出错。
$ gcloud info
Account: [projectname@appspot.gserviceaccount.com]
Project: [projectname]
Current Properties:
[core]
project: [projectname]
account: [projectname@appspot.gserviceaccount.com]
disable_usage_reporting: [True]
我尝试向IAM中的上述帐户添加以下权限:
运行Google Build时,使用的是哪个服务帐户?如何更改权限以允许自动部署功能?
答案 0 :(得分:2)
https://cloud.google.com/functions/docs/bestpractices/testing#continuous_testing_and_deployment
中记录了使用Cloud Build部署Cloud Functions。该页面的指导是:
- 要部署Cloud Functions,您可能需要将Cloud Functions Developer角色分配给Cloud Build服务帐户(PROJECT_NUMBER@cloudbuild.gserviceaccount.com)。
- 如果您使用Cloud Functions Developer角色,则还需要向Cloud Functions Runtime服务帐户(PROJECT_ID@appspot.gserviceaccount.com)授予IAM Service Account User role。
Cloud Build服务帐户为PROJECT_NUMBER@cloudbuild.gserviceaccount.com,如果您在控制台中查找该帐户,则只会有一个*@cloudbuild*
的服务帐户