Search code examples
google-cloud-platformgoogle-cloud-buildgoogle-cloud-scheduler

How to trigger a Google Cloud Build job periodically from Google cloud scheduler


I configured a cloud schedular job following enter link description here

But find error status: "INVALID_ARGUMENT". did not understand from where it came from. any suggestion to fix this, would be grateful.


Solution

  • You need to follow the bellow steps to trigger:

    1.- Create a new Service Account and add the "Cloud Build Service Account" and "Cloud Scheduler Service Agent" roles to it.

    2.- The HTTP method should be "post".

    3.- You must specify in the body field the "repoName" and the "branchName". Use the below as example.

    {
      "repoName": "MyRepo",
      "branchName": "MyBranch"
    }
    

    4.- Select "Add OAuth token" as Auth header.

    5.-Assign the created SA to your Cloud Scheduler Job that want to use to trigger your cloud Build job.

    6.-Use this value "https://www.googleapis.com/auth/cloud-platform" as Scope

    Once you have these changes, you will be able to execute the trigger.