gcloud - ERROR: (gcloud.app.deploy) Permissions error fetching application

gcloud - ERROR: (gcloud.app.deploy) Permissions error fetching application

我正在尝试在 google 云上部署节点 js 应用程序但出现以下错误 -

Step #1: ERROR: (gcloud.app.deploy) Permissions error fetching application [apps
/mytest-240512]. Please make sure you are using the correct project ID and that
you have permission to view applications on the project.

我正在 运行 执行命令 -

gcloud builds submit . --config cloudbuild.yaml

我的 cloudbuild.yaml 文件看起来像 -

steps:
  #install
  - name: 'gcr.io/cloud-builders/npm'
    args: ['install']

   #deploy
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['app', 'deploy']

将应用程序部署到 App Engine 的最常见方法是使用 gcloud app deploy ...

当您对 App Engine Flex 使用 gcloud app deploy 时,该服务使用 Cloud Build。

使用 Cloud Build 进行部署也是完全可能|合理的,只是涉及更多。

我没有尝试过,但我认为,如果您希望使用 Cloud Build 执行部署,您将需要确保 Cloud Build 服务帐户具有部署到 App Engine 的权限。

这是一个 example of what you would need to do, specifically granting Cloud Build's service account the correct role

默认的 Cloud Build 服务帐户不允许访问部署 App Engine。您需要启用 Cloud Build 服务帐户才能执行部署等操作。

Cloud Build 服务帐户的格式如下:

[PROJECT_NUMBER]@cloudbuild.gserviceaccount.com
  • 转到 Google 云控制台 -> IAM 和管理 -> IAM。
  • 找到服务帐户并单击铅笔图标。
  • 将角色 "App Engine Deployer" 添加到服务帐户。

等待几分钟,让服务帐户进行全局更新,然后重试。

两个命令可以处理所需的权限(如果您安装并验证了 gcloud sdk,则在您的终端中 运行 或在您的项目的云 shell 中 运行):

export PROJECT_ID=[[put your project id here]]
export PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")

gcloud iam service-accounts add-iam-policy-binding ${PROJECT_ID}@appspot.gserviceaccount.com \
--member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \
--role=roles/iam.serviceAccountUser \
--project=${PROJECT_ID}
```
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member=serviceAccount:${PROJECT_NUMBER}@cloudbuild.gserviceaccount.com \
--role=roles/appengine.appAdmin 

我今天遇到了同样的错误,我的解决方法是 运行: $ gcloud auth login 在控制台上。

这将打开一个新的浏览器选项卡,供您使用有权访问您要部署的项目的凭据登录。

在那之后我能够部署到 gcloud。

ps.: 我不确定这是最好的方法,但我将此作为可能的解决方案,因为这是我通常解决此问题的方法。最坏的情况,我会接受纠正并学习新东西。