This page explains how to create manual triggers to build code in source repositories. Manual triggers can be used to invoke builds manually, with the ability to override defined substitution variable values at invocation time prior to running a build. You can also schedule manual triggers to automatically run at a specific time.
To learn how to start builds manually using the gcloud CLI or the Cloud Build API, see Starting builds manually.
Before you begin
Enable the Cloud Build API.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. 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.
- Have your source code ready.
Manual triggers
Manual triggers enable you to set up builds that are only executed when you invoke your trigger on connected repositories. For example, you create a pipeline for deploying your source code to a staging or production environment. You might want to automate your workflow, but are only looking to execute builds manually. You can define manual triggers to do so.
Manual triggers enable you to manually invoke builds by:
- Fetching source code from a hosted repository with a specified branch or tag.
- Parameterizing your build with substitutions that don't need to be passed in manually each time you execute a build.
- Overriding defined substitution variable values at invocation time prior to invoking a build.
If you want to execute builds from your local working directory instead of a hosted repository
or want to submit builds without creating a trigger, you can run the following
gcloud command in your working directory:
gcloud builds submit --config BUILD_CONFIG SOURCE_CODE
Where:
- BUILD_CONFIG is the path to the build config file.
- SOURCE_CODE is the path or URL source code.
To learn more about how to use the gcloud command to start builds manually
in your local directory, see Starting builds manually.
Creating manual triggers
Console
To create a manual trigger:
Open the Triggers page:
Select your project from the top of the page and click Open.
Click Create trigger.
Enter the following trigger settings:
- Name: A name for your trigger.
Region: Select the region for your trigger.
- If you select global as the region, Cloud Build uses the default pool to run your build.
- If you select a non-global region and the build config file associated with the trigger specifies a private pool, Cloud Build uses the private pool to run your build. In this case, the region you specify in your trigger must match the region where you created your private pool.
- If you select a non-global region and the build config file associated with the trigger does not specify a private pool, Cloud Build uses the default pool to run your build in the same region as your trigger.
Description (Optional): A description for your trigger.
Event: Select Manual invocation to set up your trigger so that builds only run when the trigger is manually invoked.
Source: Select the repository to build when the manual trigger runs.
Repository generation: Select 2nd gen.
Branch or Tag: Set one of the following:
- Branch: Set a trigger to build on this branch. You must specify a literal value. Regular expressions aren't supported.
- Tag: Set a trigger to build on this tag. You must specify a literal value. Regular expressions aren't supported.
Configuration: Select the build config file located in your remote repository or create an inline build config file to use for your build.
- Type: Select the type of configuration to use for your build.
- Cloud Build configuration file (yaml or json): Use a build config file for your configuration.
- Dockerfile: Use a
Dockerfilefor your configuration.
Location: Specify the location for your configuration.
- Repository: If your config file is located in your
remote repository, provide the location of your
build config file, the
Dockerfiledirectory, or the buildpacks directory. If your build config type is aDockerfileor a buildpack, you will need to provide a name for the resulting image and optionally, a timeout for your build. When you've provided theDockerfileor buildpack image name, you'll see a preview of thedocker buildorpackcommand that your build will execute. - Inline: If you selected Cloud Build configuration file (yaml or json) as your configuration option, you can specify your build config inline. Click Open Editor to write your build config file in the Google Cloud console using YAML or JSON syntax. Click Done to save your build config.
- Repository: If your config file is located in your
remote repository, provide the location of your
build config file, the
- Type: Select the type of configuration to use for your build.
Click Create to create your manual trigger.
gcloud
To create a manual trigger:
- Open a terminal window.
Run the following
gcloudcommand to create a build trigger in your project:gcloud builds triggers create manual \ --region=REGION \ --name=TRIGGER_NAME \ --repository=projects/PROJECT_ID/locations/REGION/connections/CONNECTION_NAME/repositories/REPO_NAME \ --branch=BRANCH_NAME \ --build-config=BUILD_CONFIG_FILE \