This page explains how to run builds on a pre-defined schedule using the Google Cloud console. To schedule builds, you must create a manual trigger and then invoke the trigger using Cloud Scheduler.
Before you begin
-
Enable the Cloud Build API.
- Have your source code ready.
- If you have not already, create a manual trigger. You can only schedule builds if your trigger is a manual trigger.
Scheduling builds
After you have created a manual trigger, you are ready to schedule your build.
To schedule your build:
Open the Triggers page:
Locate the row containing the name of the manual trigger you want to run on schedule.
Click on the menu (vertical ellipses) located at the right end of the row containing your trigger.
Click Run on schedule to schedule your build.
You will see the Run trigger on schedule panel on the right side.
Enable the Cloud Scheduler API.
You will only be prompted to enable the Cloud Scheduler API the first time you schedule a build.
Select the service account you want Cloud Scheduler to use when invoking your trigger.
We recommend selecting the default scheduling service account, which has the following format where PROJECT_ID is the project ID for your project:
cloud-build-trigger-scheduler@PROJECT_ID.iam.gserviceaccount.com
When you select the default scheduling service account, it will automatically be created for you with the Cloud Build Editor IAM role granted. We recommend you don't delete this service account since it is used by Cloud Scheduler to schedule builds. If you accidentally delete this service account, or revoke any of its IAM permissions, you can navigate to the IAM page to manually add the service account and grant it the Cloud Build Editor role. You may need to wait up to an hour for any existing Cloud Scheduler jobs to resume after recreating the service account.
Click Continue.
If you do not have a region selected, you may be prompted to select a region for your Cloud Scheduler jobs before proceeding to the next step. When you select a region, an App Engine application will be automatically created in your project. You cannot change the region for your project later on. To learn more, see Supported regions.
Enter the following Cloud Scheduler job settings:
- Name: A name for your Cloud Scheduler job.
- Description (Optional): A description for your Cloud Scheduler job.
- Frequency: Select how frequently you would like your trigger to
run. You can choose a frequency from the drop-down menu or enter a
custom value using cron syntax. For example, if you want your manual trigger to
run everyday at 6 AM, you can specify your frequency in cron syntax as
0 6 * * *
. To learn more about cron syntax, see Configuring cron job schedules. - Time Zone: Select your time zone.
Click Create to create your Cloud Scheduler job.
You can create multiple scheduler jobs for each manual trigger.
If you would like to view your Cloud Scheduler job, click View. Otherwise, click Done to close the panel.
Updating your Cloud Scheduler job
If you update the Revision field in your manual trigger, you'll need to manually update the Cloud Scheduler job associated with your trigger. For example, if you update the branch name for your manual trigger, you will need to manually update the name of the branch in your job.
To update your Cloud Scheduler job:
Open the Cloud Scheduler page:
You will see a list of your Cloud Scheduler jobs.
[Optional] Identify the Cloud Scheduler job associated with your trigger:
Obtain your trigger ID by running the following command, where where TRIGGER_NAME is the name of your trigger:
gcloud builds triggers describe TRIGGER_NAME
Take note of your trigger ID.
Enter your trigger ID into the filter bar at the top of the table.
You will see the list of your Cloud Scheduler jobs associated with your trigger.
Click on the row containing the name of the job you want to update.
Click Edit at the top of the page.
You will see a form to update your Cloud Scheduler job.
In the Body field, update your revision.
Click Update.
You have now updated the revision associated with your trigger for your Cloud Scheduler job.
Removing your Cloud Scheduler job
Deleting or disabling your trigger will not automatically delete or disable all Cloud Scheduler jobs that were automatically created when you scheduled the trigger. Your jobs will exist and builds may continue to be invoked.
To make sure your trigger will no longer run at a specified time, delete your Cloud Scheduler job.
Next steps
- Learn how to start builds manually using
gcloud
commands or the Cloud Build API. - Learn how to create and manage triggers.
- Learn how to view build results.