Search code examples
google-cloud-platformgoogle-cloud-functionsgoogle-cloud-build

In GCP, through Cloudbuild how can I ensure that only those steps get triggered for which changes have happened in file


My issue is that, given the below yaml file, if I'm making changes for example in any file of "dir: process/cbd-bu-data", Cloud Build runs all the steps serially when triggered. This leads to wastage of time.

I want that only that step runs in cloudbuild for which the changes have been made in file of that directory. What should I do to achieve this?

Here's my cloudbuild.yaml file:

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  

Solution

  • With your use case then the best approach would be having different triggers (3 in your use case) that listen to different tags or branches, being each of these specific for the file changes that you want to listen to. At the moment making Cloud Build steps execute when a certain file changes is not available.