首页 > 解决方案 > Gitlab 管道失败,即使部署发生在 GCP 上

问题描述

我刚刚在 Gitlab 上创建了我的第一个 CI/CD 管道,它为 Next.js 应用程序创建了一个 docker 容器,并将其部署在 Google Cloud Run 上。

我的 cloudbuild.yaml:

# File: cloudbuild.yaml
steps:
    # build the container image
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'build', '-t', 'gcr.io/$PROJECT_ID/inook-web', '.' ]
    # push the container image
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'push', 'gcr.io/$PROJECT_ID/inook-web']
    # deploy to Cloud Run
  - name: "gcr.io/cloud-builders/gcloud"
    args: ['run', 'deploy', 'inook-web', '--image', 'gcr.io/$PROJECT_ID/inook-web', '--region', 'europe-west1', '--platform', 'managed', '--allow-unauthenticated']

我的 .gitlab-ci.yml:

# File: .gitlab-ci.yml
image: docker:latest

stages:          # List of stages for jobs, and their order of execution
  - deploy-test
  - deploy-prod

deploy-test:
  stage: deploy-test
  image: google/cloud-sdk
  services:
    - docker:dind
  script:
    - echo $GCP_SERVICE_KEY > gcloud-service-key.json # Google Cloud service accounts
    - gcloud auth activate-service-account --key-file gcloud-service-key.json
    - gcloud config set project $GCP_PROJECT_ID
    - gcloud builds submit . --config=cloudbuild.yaml

我在 CI/CD 管道中收到以下错误消息: https ://ibb.co/ZXLWrj1

但是,实际上在 GCP 上部署成功:https ://ibb.co/ZJjtXzG

知道我能做些什么来修复管道错误吗?

标签: dockergoogle-cloud-platformcontinuous-integrationgitlab-cigoogle-cloud-run

解决方案


对我有用的是为 gcloud 构建提交添加一个自定义存储桶以将日志推送到。感谢@slauth 为我指明了正确的方向。

更新命令:

gcloud builds submit . --config=cloudbuild.yaml --gcs-log-dir=gs://inook_test_logs

推荐阅读