Connect to a GitHub Enterprise host | Cloud Build | Google Cloud Documentation
Skip to main content Console English Deutsch Español Español – América Latina Français Indonesia Italiano Português Português – Brasil עברית 中文 – 简体 中文 – 繁體 日本語 한국어 Sign in Cloud Build Start free Home Documentation Application development Cloud Build Guides Connect to a GitHub Enterprise host Stay organized with collections Save and categorize content based on your preferences.
This page explains how to connect a GitHub Enterprise host to Cloud Build. Before you begin Enable the Cloud Build and Secret Manager APIs, if any are 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 . Enable the APIs Ensure that you have the latest version of GitHub Enterprise. Ensure you map a custom domain to your GitHub Enterprise host and have a valid SSL certificate for your host. If your GitHub Enterprise instance is hosted in a private network, see Build repositories from GitHub Enterprise in a private network prior to completing instructions on this page. Required IAM permissions To connect your GitHub Enterprise host, grant the Cloud Build Connection Admin ( roles/cloudbuild.connectionAdmin ) role to your user account.
To add the required roles to your user account, see Configuring access to Cloud Build resources . To learn more about IAM roles associated with Cloud Build, see IAM roles and permissions . To create connections using gcloud installation steps, grant the Secret Manager Admin role ( roles/secretmanager.admin ) to the Cloud Build Service Agent by running the following command in your Google Cloud project: PN=$(gcloud projects describe ${ PROJECT_ID } --format="value(projectNumber)") CLOUD_BUILD_SERVICE_AGENT="service- ${ PN } @gcp-sa-cloudbuild.iam.gserviceaccount.com" gcloud projects add-iam-policy-binding ${ PROJECT_ID } \ --member="serviceAccount: ${ CLOUD_BUILD_SERVICE_AGENT } " \ --role="roles/secretmanager.admin" If your GitHub Enterprise instance is hosted in a private network, see Build repositories from GitHub Enterprise in a private network to learn about additional IAM roles required prior to host connection.
Connect to a GitHub Enterprise host Console To connect your GitHub Enterprise host to Cloud Build: Open the Repositories page in the Google Cloud console. Open the Repositories page You will see the Repositories page. In the project selector in the top bar, select your Google Cloud project. At the top of the page, select the 2nd gen tab. Click Create host connection to connect a new host to Cloud Build. On the left panel, select GitHub Enterprise as your source provider.
In the Configure Connection section, enter the following information: Region : Select a region for your connection. Name : Enter a name for your connection. In the Host details section, go to Host URL and enter the host URL for your connection. For example, github.example.com . Optional: If you want to manage the encryption keys used to encrypt the access tokens for your GitHub Enterprise repositories, then go to the Encryption section and choose a Cloud Key Management Service key.
For more information, see Enable customer-managed encryption keys for Secret Manager . In the Networking section, under Connection type , select one of the following options: Public internet : Select this option if your instance is accessible using the public internet. Private network : Select this option if your instance is hosted on a private network. Then, configure the following: CA Certificate : Click Browse to upload your self-signed certificate.
Under Service Directory service , selection the location for your service: In project CURRENT_PROJECT In another project Enter manually Enter the following information: Project : If you selected In another project or Enter manually , then enter or select your Google Cloud project ID from the drop-down menu. Region : This field pre-selects the region of your connection. The region specified for your service must match the region associated with your connection.
Namespace : Select the namespace of your service. Service : Select the service name in your namespace. Click Connect . After you click the Connect button, you'll be asked to create a GitHub App in your GitHub Enterprise host and install the app in a user account or organization. An authentication token from your GitHub Enterprise host is created and stored in this project as a Secret Manager secret. You can revoke access by uninstalling or deleting the GitHub app from your host at any time.
Cloud Build stores the authentication data of the created GitHub App as secrets in Secret Manager in your project. This data includes your private key and webhook secret. The private key is used as an authentication method to access the API of the Enterprise Server. The webhook secret is used to validate the events sent from the server to Cloud Build. The Cloud Build Service Agent account ( service-{projectNumber}@gcp-sa-cloudbuild.iam.gserviceaccount.com ) is used to access your secret.
To view your secret, see List secrets and view secret details . After authorizing the Cloud Build GitHub App, you will be redirected to the Cloud Build Repositories page. gcloud To connect your GitHub Enterprise host to Cloud Build using gcloud commands, complete the following steps: Enter the following command to create a GitHub Enterprise connection: gcloud builds connections create github - enterprise CONNECTION_NAME \ -- host - uri = HOST_URI -- region = REGION Where: CONNECTION_NAME is a name for your GitHub Enterprise host connection in Cloud Build.
HOST_URI is the URI of your GitHub Enterprise instance. For example, https://mmy-ghe-server.net . REGION is the region for your connection. If your GitHub Enterprise instance is in a private network, specify your Service Directory resource. You can also specify your CA certificate. --service-directory-service=projects/ PROJECT_ID /locations/ REGION /namespaces/ NAMESPACE /services/ SERVICE_NAME \ --ssl-ca-file= SSL_CA_FILEPATH Where: PROJECT_ID is your Google Cloud project ID.
REGION is the region for your connection. NAMESPACE is the namespace for your service. SERVICE_NAME is the name of your service in your namespace. SSL_CA_FILEPATH is the path to your CA certificate. After running the gcloud builds connections... command, you will receive a link to install the Cloud Build GitHub app. Follow the link returned in the previous step to create and install the Cloud Build GitHub App on your enterprise server.
Enter the following command to verify your connection: gcloud builds connections describe CONNECTION_NAME -- region = REGION Where: CONNECTION_NAME is the name of your GitHub Enterprise host connection in Cloud Build. REGION is the region for your connection. If the installationState field is set to COMPLETE , you have successfully installed the connection. Otherwise, the installationState field provides a link for additional steps required.
Connect to a GitHub Enterprise host programmatically To connect your GitHub Enterprise host programmatically to Cloud Build, you must install the GitHub app by completing the following steps: Register a new GitHub app. For example, you may register a new GitHub app at https://my-ghe-server.net/settings/apps/new . Complete the fields on the page: GitHub App Name : Enter a name for your app. Homepage URL : Enter a URL for your GitHub Enterprise Server.
Clear the box for Expire user authorization tokens . In the Webhook section, complete the following steps: Active : Check the box to activate your webook. Webhook URL : Enter your webhook URL. For example, https://cloudbuild.googleapis.com/v2/projects/{PROJECT_NUMBER}/locations/{REGION}/connections:processWebhook
The rest of this page is on the live site.