This page explains how to run builds on a predefined schedule using the
Google Cloud console. To schedule builds, you must [create a manual trigger](https://docs.cloud.google.com/build/docs/automating-builds/create-manual-triggers#creating_manual_triggers) and then invoke the trigger using Cloud Scheduler.

## Before you begin

-


  Enable the Cloud Build API, if it is not already enabled.


  **Roles required to enable APIs**


  To enable APIs, you need the `serviceusage.services.enable` permission. If you
  created the project, then you likely already have this permission through the
  Owner role (`roles/owner`). Otherwise, you can get this permission through the
  Service Usage Admin role (`roles/serviceusage.serviceUsageAdmin`).
  [Learn how to grant roles](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

  [Enable the API](https://console.cloud.google.com/apis/enableflow?apiid=cloudbuild.googleapis.com&redirect=https://docs.cloud.google.com/build/docs/schedule-builds)
- Have your source code ready.
- If you haven't already, [create a manual trigger](https://docs.cloud.google.com/build/docs/automating-builds/create-manual-triggers). **You can only schedule builds if your trigger is a manual trigger.**
- If you plan to use a [user-specified service account](https://docs.cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts.md.txt) for your build trigger, make sure to have the email address of that service account ready. You will need to grant the scheduling service account permission to use it.

## Scheduling builds

After you have [created a manual trigger](https://cloud.google.com/build/docs/automating-builds/create-manual-triggers), you are ready to schedule your build.

To schedule your build:

1. Open the **Triggers** page:

   <br />

   [Open the Triggers page](https://console.cloud.google.com/cloud-build/triggers)

   <br />

2. Locate the row containing the name of the manual trigger you want to run
   on schedule.

3. Click the **Actions** menu

   located at the right end of the row containing your trigger.

4. Click **Run on schedule** to schedule your build.

   You will see the **Run trigger on schedule** panel on the right side.
5. Enable the **Cloud Scheduler** API.

   You will only be prompted to enable the **Cloud Scheduler** API the first
   time you schedule a build.
6. 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 <var translate="no">PROJECT_ID</var> 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](https://console.cloud.google.com/iam-admin/iam)
   to manually add the service account and grant it the **Cloud Build
   Editor** role. You might need to wait up to an hour for any existing
   Cloud Scheduler jobs to resume after recreating the service account.

   If your manual trigger uses a
   [user-specified service account](https://docs.cloud.google.com/build/docs/securing-builds/configure-user-specified-service-accounts.md.txt),
   you must also grant the **Service Account User** (`roles/iam.serviceAccountUser`)
   role to the default scheduling service account on your user-specified service
   account. Without this role, Cloud Scheduler won't have permission to
   run the trigger.
7. Click **Continue**.

   If you don't have a region selected, you might 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](https://docs.cloud.google.com/scheduler/docs.md.txt#supported_regions).
8. 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](https://docs.cloud.google.com/scheduler/docs/configuring/cron-job-schedules.md.txt).
   - **Time Zone**: Select your time zone.
9. Click **Create** to create your Cloud Scheduler job.

   You can create multiple scheduler jobs for each manual trigger.
10. 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](https://docs.cloud.google.com/build/docs/automating-builds/create-manual-triggers), 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:

1. Open the **Cloud Scheduler** page:

   <br />

   [Open the Cloud Scheduler page](https://console.cloud.google.com/cloudscheduler)

   <br />

   You will see a list of your Cloud Scheduler jobs.
2. \[Optional\] Identify the Cloud Scheduler job associated with your trigger:

   1. Obtain your trigger ID by running the following command, where
      where <var translate="no">TRIGGER_NAME</var> is the name of your trigger:

          gcloud builds triggers describe TRIGGER_NAME

   2. Take note of your trigger ID.

   3. 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.
3. Click the row containing the name of the job you want to update.

4. Click **Edit** at the top of the page.

   You will see a form to update your Cloud Scheduler job.
5. In the **Body** field, update your revision.

6. Click **Update**.

You have now updated the revision associated with your trigger for your
Cloud Scheduler job.

## Removing your Cloud Scheduler job

[Deleting](https://docs.cloud.google.com/build/docs/automating-builds/create-manage-triggers.md.txt#deleting_a_build_trigger) or [disabling](https://docs.cloud.google.com/build/docs/automating-builds/create-manage-triggers.md.txt#disabling_a_build_trigger)
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 might continue to be invoked.

To make sure your trigger will no longer run at a specified time,
[delete your Cloud Scheduler job](https://docs.cloud.google.com/scheduler/docs/creating.md.txt#console_1).

## Next steps

- Learn how to [start builds manually](https://docs.cloud.google.com/build/docs/running-builds/start-build-manually) using `gcloud` commands or the Cloud Build API.
- Learn how to [create and manage triggers](https://docs.cloud.google.com/build/docs/automating-builds/create-manage-triggers.md.txt).
- Learn how to [view build results](https://docs.cloud.google.com/build/docs/view-build-results.md.txt).
- Learn how to [prevent duplicate requests to Google Cloud API targets](https://docs.cloud.google.com/scheduler/docs/configuring/deduplicate-job-requests.md.txt#deduplicate-google-api-targets) when Cloud Scheduler retries a job.