Bitbucket 管道部署到 gCloud AppEngine 导致 [13] 发生内部错误

Bitbucket pipelines deploy to gCloud AppEngine causes [13] An internal error occurred

我正尝试在我的项目中使用 bitbucket 管道。我使用节点。

当我从 Mac 或 Windows 手动 运行 gcloud app deploy 时 - 它工作正常,部署成功完成。但是从 bitbucket 管道它失败并显示 错误响应:[13] 发生内部错误。

这是我通过 运行 gcloud app deploy --verbosity=debug:

获得的堆栈跟踪
Updating service [default]...
.DEBUG: Operation [apps/my-project/operations/a68a837e-edcf-4987-83db-d9b47f4309ae] not complete. Waiting to retry.
.......DEBUG: Operation [apps/my-project/operations/a68a837e-edcf-4987-83db-d9b47f4309ae] complete. Result: {
    "metadata": {
        "target": "apps/my-project/services/default/versions/20180915t180908", 
        "method": "google.appengine.v1.Versions.CreateVersion", 
        "user": "bitbucket-works@my-project.iam.gserviceaccount.com", 
        "insertTime": "2018-09-15T18:09:46.693Z", 
        "endTime": "2018-09-15T18:09:49.655Z", 
        "@type": "type.googleapis.com/google.appengine.v1.OperationMetadataV1"
    }, 
    "done": true, 
    "name": "apps/my-project/operations/a68a837e-edcf-4987-83db-d9b47f4309ae", 
    "error": {
        "message": "An internal error occurred.", 
        "code": 13
    }
}
failed.

DEBUG: (gcloud.app.deploy) Error Response: [13] An internal error occurred.
Traceback (most recent call last):
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 839, in Execute
    resources = calliope_command.Run(cli=self, args=args)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 770, in Run
    resources = command_instance.Run(args)
  File "/tmp/google-cloud-sdk/lib/surface/app/deploy.py", line 90, in Run
    parallel_build=False)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 625, in RunDeploy
    flex_image_build_option=flex_image_build_option)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/command_lib/app/deploy_util.py", line 431, in Deploy
    extra_config_settings)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/appengine_api_client.py", line 207, in DeployService
    poller=done_poller)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/operations_util.py", line 315, in WaitForOperation
    sleep_ms=retry_interval)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 254, in WaitFor
    sleep_ms, _StatusUpdate)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 316, in PollUntilDone
    sleep_ms=sleep_ms)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/core/util/retry.py", line 229, in RetryOnResult
    if not should_retry(result, state):
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/waiter.py", line 310, in _IsNotDone
    return not poller.IsDone(operation)
  File "/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/app/operations_util.py", line 184, in IsDone
    encoding.MessageToPyValue(operation.error)))
OperationError: Error Response: [13] An internal error occurred.
ERROR: (gcloud.app.deploy) Error Response: [13] An internal error occurred.

我的 bitbucket-pipelines.yml:

pipelines:
  default:
    - step:
        name: Test and deployment
        image: node:8.9
        script: # Modify the commands below to build your repository.
          - npm install
          - npm test
          - npm build
          # Downloading the Google Cloud SDK
          - curl -o /tmp/google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-216.0.0-linux-x86_64.tar.gz
          - tar -xvf /tmp/google-cloud-sdk.tar.gz -C /tmp/
          - /tmp/google-cloud-sdk/install.sh -q
          - source /tmp/google-cloud-sdk/path.bash.inc
          # Setup
          - echo $GCLOUD_CLIENT_SECRET > client-secret.json
          - gcloud auth activate-service-account --key-file client-secret.json
          - gcloud config set project $GCLOUD_PROJECT
          - gcloud -q app deploy --verbosity=debug

我的 .gcloudignore:

.gcloudignore
.git
.gitignore

# Node.js dependencies:
node_modules/
design/

我在 Whosebug 和 Google 上找到了一些解决方案,但没有任何效果。我尝试了不同版本的 Google Cloud SDK - 但结果是一样的。 提前感谢您的帮助。

终于解决了

TL;DR:

在 IAM 和管理页面上为您的 bitbucket 成员添加 Cloud Build Editor 角色。


我已将 GCloud 版本更新到 218,它开始显示有关错误的更多信息(不仅仅是发生内部错误):

OperationError: Error Response: [13] Permission to create cloud build is denied. 'Cloud Build Editor' role is required for the deployment: https://cloud.google.com/cloud-build/docs/securing-builds/configure-access-control#permissions.

问题是 GCloud 上的 bitbucket 成员缺少权限。似乎这是最近添加的要求,因为没有任何手册有相关信息。

要解决此问题,您应该在 IAM 和管理页面上为您的 bitbucket 成员添加 Cloud Build Editor 角色。

希望对您有所帮助。