Connect to a GitHub Enterprise repository

Stay organized with collections Save and categorize content based on your preferences.

This page explains how to connect a GitHub Enterprise repository to Cloud Build.

Before you begin

  • Enable the Cloud Build and Secret Manager APIs.

    Enable the APIs

  • Follow the instructions to connect a GitHub Enterprise host.
  • Ensure you have admin access on repositories that you want to enable GitHub Enterprise triggers for.

Connecting to a GitHub Enterprise repository

This section explains how you can map your Cloud project to the GitHub app you created. If you have not created the app yet, follow the instructions in Connect to a GitHub Enterprise host.

Console

  1. Open the Triggers page in the Google Cloud console.

    Open the Triggers page

  2. Click Connect Repository.

  3. Under Select source, click on GitHub Enterprise.

  4. Select your Host Connection (GitHub Enterprise Config) from the drop-down menu.

  5. Click Continue.

  6. Authorize your application.

  7. Under Select repository, select your GitHub account and Repository from the drop-down menu.

API

To install the GitHub app on the appropriate GitHub user account or organization and connect it to a Cloud Build project:

  1. Navigate to the URL associated with the GitHub app you created in the previous section:

       https://host-url/organizations/org-name/settings/apps/app-name/
    

    Where:

    • host-url is host url of your GitHub Enterprise instance.
    • org-name is the name of the organization where you created your project.
    • app-name is the name of your GitHub app.
  2. Install the app on your user account or organization via the URL.

    Once the app has been installed, take note of the installation ID associated with the app. The installation ID can be found in the URL after the app has been installed.

  3. Create a JSON file with the following contents:

    {
     "Id": installation-id,
     "project_id": "project-id",
     "repository_setting_list": {
            "repository_settings": {
            "owner": "owner",
            "name": "repo-name",
          },
          "repository_settings": {
            "owner": "owner",
            "name": "repo-name-additional"
          },
         …
     },
        "enterprise_config_resource_name": "projects/project-number/githubEnterpriseConfigs/id"
    }
    

    Where:

    • installation-id is the installation id of the GitHub app. Note: This value is an integer and does not require quotes.
    • project-id is the Cloud project associated with the installation.
    • owner is the owner of the GitHub repository.
    • repo-name is the name of the GitHub repository.
    • [OPTIONAL] repo-name-additional is the name of an additional GitHub repository.
    • project-number is the number of the Cloud project.
    • id is the host connection ID obtained from the Host Connections tab on the Manage repositories page.
  4. Enter the following curl command in your terminal, where project-id is the Cloud project ID:

     curl -X POST -H "Authorization: Bearer "$(gcloud auth print-access-token) -H "Content-Type: application/json; charset=utf-8" https://cloudbuild.googleapis.com/v1/projects/${PROJECT_ID}/installations -d @installation.json
    

The repositories associated with your installation are now viewable on the Triggers page under the Inactive tab.

Next steps