google-cloud-platform - 在 GCP 中,通过 Cloudbuild 如何确保仅触发文件中发生更改的那些步骤

标签 google-cloud-platform google-cloud-functions google-cloud-build

我的问题是,鉴于下面的 yaml 文件,如果我在“dir: process/cbd-bu-data”的任何文件中进行更改,Cloud Build 会在触发时按顺序运行所有步骤。这会导致时间浪费。

我希望只有该步骤在 cloudbuild 中运行,并且在该目录的文件中进行了更改。我应该怎么做才能实现这一目标?

这是我的 cloudbuild.yaml文件:

steps: 
  - args: 
      - beta
      - functions
      - deploy
      - "--runtime=python37"
      - "--trigger-http"
      - "--entry-point=process_cbd_group_data"
      - process_cbd_group_data
      - "--region=us-central1"
    dir: process/cbd-group-data
    name: gcr.io/cloud-builders/gcloud
  - args: 
      - beta
      - functions
      - deploy
      - "--runtime=python37"
      - "--trigger-http"
      - "--entry-point=process_cbd_bu_data"
      - process_cbd_bu_data
      - "--region=us-central1"
    dir: process/cbd-bu-data
    name: gcr.io/cloud-builders/gcloud
  - args: 
      - beta
      - functions
      - deploy
      - "--runtime=python37"
      - "--trigger-http"
      - "--entry-point=process_cbd_structure_data"
      - process_cbd_structure_data
      - "--region=us-central1"
    dir: process/cbd-structure-data
    name: gcr.io/cloud-builders/gcloud  

最佳答案

您无法通过一个 cloudbuild 来做到这一点。您可以做的是使用 --included-files 选项创建三个不同的构建触发器。我认为用分支或标签完成同样的事情并不方便,就像我在另一个答案中读到的那样。阅读 documentation更多细节。
您的 git 存储库布局:

function_one/
   main.py
   cloudbuild.yaml

function_two/
   main.py
   cloudbuild.yaml

function_three/
   main.py
   cloudbuild.yaml

cloudbuild.yaml
父 cloudbuild.yaml 的布局:
steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        cloud beta builds triggers create github build_one --included-files "function_one/*" --repo-name=XXX --repo-owner=XXX --branch-pattern=$BRANCH_NAME
        cloud beta builds triggers create github build_two --included-files "function_two/*" --repo-name=XXX --repo-owner=XXX --branch-pattern=$BRANCH_NAME
        cloud beta builds triggers create github build_three --included-files "function_three/*" --repo-name=XXX --repo-owner=XXX --branch-pattern=$BRANCH_NAME
子cloudbuild.yaml的布局:
steps: 
  - args: 
      - functions
      - deploy
      - "--runtime=python37"
      - "--trigger-http"
      - "--entry-point=process_cbd_group_data"
      - process_cbd_group_data
      - "--region=us-central1"
    name: gcr.io/cloud-builders/gcloud

关于google-cloud-platform - 在 GCP 中,通过 Cloudbuild 如何确保仅触发文件中发生更改的那些步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61011558/

相关文章:

python - 带有 Google 容器注册表的 Docker SDK

firebase - Firebase的Cloud Functions是否会使firebase-queue过时?

docker - 使用 Dockerfile 从 Google Cloud Build 部署到 Google App Engine Flex 环境

pyspark - GCP - GKE 与 Dataproc 的 Spark

Kubernetes 上的 Jenkins 未加载外部卷中的/var/jenkins_home/init.groovy.d 文件

javascript - 如何在创建时向新文档添加字段?

firebase - 为什么我无法再部署函数(错误 503)?

google-cloud-build - 是否可以在 Google Cloud Build 中动态生成标签?

google-cloud-platform - Google Cloud 构建 10 分钟后超时

google-cloud-platform - GCP 错误 : Quota 'GPUS_ALL_REGIONS' exceeded. 全局限制 : 0. 0