This page explains how to connect a GitHub Enterprise repository to Cloud Build. To learn more about Cloud Build repositories, see Cloud Build repositories .
Before you begin
-
Enable the Cloud Build and Secret Manager APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles .
- Follow the instructions to connect a GitHub Enterprise host .
- Ensure you have administrator access on repositories where you want to enable GitHub Enterprise triggers.
Connect to a GitHub Enterprise repository
Console
To connect a GitHub Enterprise repository to a host connection, complete the following steps:
-
Open the Repositoriespage in the Google Cloud console.
You see the Repositoriespage.
-
At the top of the page, select the 2nd gentab.
-
Click Link Repositoryto link repositories from your connection.
You see the Link repositoriespanel.
-
In the Link Repositoriespanel, enter the following information:
- Connection: Select a connection from the drop-down menu.
-
Repository: Select a repository to link to your connection.
-
Repository Name: Enter a name for your repository.
- Generated: Select this option for Cloud Build to automatically generated repository names on your behalf for selected repositories.
-
Manual: Select this option to manually specify names for your selected repositories.
If you select Manual, you can modify the names for your selected repositories in the Repository namessection.
-
Click Linkto link your repository to your connection.
You have now successfully linked your GitHub Enterprise repository to your connection.
gcloud
To add a GitHub Enterprise repository to your connection, enter the following command:
gcloud
builds
repositories
create
REPO_NAME
\
--
remote
-
uri
=
REPO_URI
\
--
connection
=
CONNECTION_NAME
--
region
=
REGION
Where:
- REPO_NAME is the name of your repository.
- REPO_URI is the link to your GitHub repository.
- CONNECTION_NAME is the name given to the GitHub Enterprise host connection created in Cloud Build from Connect to a GitHub Enterprise host .
- REGION is the region for your connection.
Terraform
To add a GitHub Enterprise repository to your connection, add the following code snippet to your Terraform configuration:
resource
"google_cloudbuildv2_repository"
"my-repository"
{
project
=
" PROJECT_ID
"
name
=
" REPO_NAME
"
location
=
:
REGION
"
parent_connection
=
google_cloudbuildv2_connection.my-connection.name
remote_uri
=
" REMOTE_URI
'
}
Where:
- PROJECT_ID is your Google Cloud project ID.
- REPO_NAME is the name of your GitHub repository.
- REGION is the region for your connection.
- URI
is the remote URI of your repository. For example,
https://github.com/myuser/myrepo.git.
Next steps
- Learn how to build repositories from GitHub Enterprise .
- Learn how to build repositories from GitHub Enterprise in a private network .
- Learn how to perform blue-green deployments on Compute Engine .
- Learn how to specify additional repositories as dependencies to your build.

