【问题标题】:Gitlab Cloud run deploy successfully but Job failedGitlab Cloud 运行部署成功但作业失败
【发布时间】:2021-11-23 08:28:11
【问题描述】:

我的 CI/CD 管道有问题, 它已成功部署到 GCP 云运行,但在 Gitlab 仪表板上,状态为失败。

我尝试将图像替换为其他一些 docker 图像,但也失败了。

 # File: .gitlab-ci.yml
image: google/cloud-sdk:alpine
deploy_int:
  stage: deploy
  environment: integration
  only:
  - integration    # This pipeline stage will run on this branch alone
  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_int.yaml




# File: cloudbuild_int.yaml
steps:
    # build the container image
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'build','--build-arg','APP_ENV=int' , '-t', 'gcr.io/$PROJECT_ID/tpdropd-int-front', '.' ]
    # push the container image
  - name: 'gcr.io/cloud-builders/docker'
    args: [ 'push', 'gcr.io/$PROJECT_ID/tpdropd-int-front']
    # deploy to Cloud Run
  - name: "gcr.io/cloud-builders/gcloud"
    args: ['run', 'deploy', 'tpd-front', '--image', 'gcr.io/$PROJECT_ID/tpdropd-int-front', '--region', 'us-central1', '--platform', 'managed', '--allow-unauthenticated']

gitlab 构建输出:

ERROR: (gcloud.builds.submit) 
The build is running, and logs are being written to the default logs bucket.
This tool can only stream logs if you are Viewer/Owner of the project and, if applicable, allowed by your VPC-SC security policy.
The default logs bucket is always outside any VPC-SC security perimeter.
If you want your logs saved inside your VPC-SC perimeter, use your own bucket.
See https://cloud.google.com/build/docs/securing-builds/store-manage-build-logs.
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

【问题讨论】:

  • 你能添加你的 GitLab CI/CD 作业输出吗?或者以其他方式解释您所说的“失败”是什么意思?
  • 您的 Gitlab 步骤是否超时?关于失败的 gitlab 错误信息是什么?
  • 我添加了 gtlab 输出
  • @AdamMarshall “失败”是 CI/CD 工作流的状态。
  • @MIkCode - 根据构建输出顶部的 ERROR: (gcloud.builds.submit) ,看起来 gcloud 命令正在返回错误状态,即使它实际上正在完成。如果命令的返回代码不是 0,GitLab 将假定作业失败 - 在这种情况下,退出代码为 1(根据构建输出中的最后一个注释)。您要么需要弄清楚提交代码返回 0 的原因,要么可以在命令末尾添加“|| true”以完全忽略错误。我强烈推荐第一个选项!

标签: google-cloud-platform gitlab


【解决方案1】:

你可以使用这个解决方法:

通过将 Viewer 角色授予运行它的服务帐户来修复它,但这感觉就像给这样的角色过多的权限。

【讨论】:

    【解决方案2】:

    我使用以下方法修复它:

    options:
      logging: CLOUD_LOGGING_ONLY
    

    在 cloudbuild.yaml 中

    【讨论】:

    • 您的答案可以通过添加有关代码的作用以及它如何帮助 OP 的更多信息来改进。
    猜你喜欢
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    • 2021-07-23
    • 2017-10-25
    • 1970-01-01
    相关资源
    最近更新 更多