Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link cloudbuild.yaml from different repository (Google Cloud Build trigger)

Basically I want to link my cloudbuild.yaml from within my testing environment to my dev environment.

I have a trigger every time I commit on my testing env, my tests run and generate a report (per the yaml). Great.

But I want to create a trigger when my dev environment commits, my tests run from my testing repository and create the reports.

like image 456
thomarkey Avatar asked Oct 28 '25 17:10

thomarkey


1 Answers

You have 2 solutions for doing this.

First, you can download your test project and run a Cloud Build from the current execution of the dev build

steps:
- name: gcr.io/cloud-builders/git
  args: ['clone', 'https://myrepo.com/testing']
- name: gcr.io/cloud-builders/gcloud
  args: ["builds", "submit"]
  dir: "testing"   # I assume that the git clone has created the testing directory

The advantage of this solution is if your Cloud Build on Test project failed, you know it synchronously and you can react on this on your Dev current build

The counterpart is that the processing time is duplicated during the test build. Indeed, the test build is performed, and the dev test continue (even in standby) to wait the test build end. You also need to set correctly the Cloud Build timeout.


Second solution is an API call to trigger manually your test Cloud Build trigger.

For this you need to customize the step bellow with:

  • The test project ID
  • The trigger UUID. You can find it in the page URL when you click on your trigger for editing it.

enter image description here

You can also change the branchName if you want

steps:
  - name: 'gcr.io/cloud-builders/gcloud'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
             curl -d '{"branchName":"master"}' -X POST -H "Content-type: application/json" -H "Authorization: Bearer $(gcloud config config-helper --format='value(credential.access_token)')" https://cloudbuild.googleapis.com/v1/projects/<PROJECT_TEST_ID>/triggers/<TRIGGER_UUID>:run

Here, you don't wait the end of the build and you save Cloud Build duration (and money), but you can't react in case of build failed.

like image 115
guillaume blaquiere Avatar answered Oct 31 '25 11:10

guillaume blaquiere



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!