Connect to a GitLab Enterprise Edition repository

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

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

Before you begin

  • Enable the Cloud Build and Secret Manager APIs.

    Enable the APIs

Connecting to a GitLab Enterprise Edition repository

Console

To connect a GitLab Enterprise Edition repository to Cloud Build using the Google Cloud console:

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

    Open the Triggers page

  2. Click Connect Repository.

    The Connect repository panel appears.

  3. Under Select source, select GitLab Enterprise Edition.

  4. Under Select Repository, select the GitLab Enterprise Edition repositories you wish to connect to Cloud Build.

  5. Click Connect to connect your repositories.

    When a repository is connected, Cloud Build configures a webhook on the repository in your GitLab Enterprise Edition instance. The repository then sends webhooks to invoke the corresponding GitLab Enterprise Edition triggers when you make changes to your repository. A repository can also be connected multiple times with multiple host connections. To learn how to manage webhooks, see Webhooks.

    To locate the webhook, you need the webhook ID. The webhook ID for each connected repository can be found in the GitLabEnterpriseConfig.

    Enter the following command to retrieve the webhook ID, where CONFIG_NAME is the name of the GitLab Enterprise Edition config:

    gcloud alpha builds enterprise-config gitlab describe --config=CONFIG_NAME
    
  6. Click Done. Optionally, click Create a trigger to create a trigger.

API

You can use the Cloud Build to programmatically manage repository connections. To connect your GitLab Enterprise Edition repository to Cloud Build using the API, use the following JSON template:

  {
    "parent": "projects/PROJECT_ID/locations/REGION/gitLabConfigs/GITLAB_ENTERPRISE_EDITION_CONFIG_NAME",
    "requests": {
      "parent": "projects/PROJECT_ID/locations/REGION/gitLabConfigs/GITLAB_ENTERPRISE_EDITION_CONFIG_NAME",
      "gitlabConnectedRepository": {
        "parent": "projects/PROJECT_ID/locations/REGION/gitLabConfigs/GITLAB_ENTERPRISE_EDITION_CONFIG_NAME",
        "repo": {
           "id": "GITLAB_ENTERPRISE_EDITION_PROJECT_NAMESPACE"
         }
       }
    }
  }

Replace the following:

  • PROJECT_ID is your Google Cloud project ID.
  • REGION is the region where your GitLab Enterprise Edition configuration is located.
  • GITLAB_ENTERPRISE_EDITION_CONFIG_NAME is the name of your GitLab Enterprise Edition configuration.
  • GITLAB_ENTERPRISE_EDITION_PROJECT_NAMESPACE the namespace of your GitLab Enterprise Edition project.

Enter the following curl command in your terminal:

  curl -X POST -H "Authorization: Bearer "$(gcloud auth print-access-token) -H "Content-Type: application/json; charset=utf-8" -H "x-goog-user-project: PROJECT_ID" https://cloudbuild.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/gitLabConfigs/GITLAB_ENTERPRISE_EDITION_CONFIG_NAME/connectedRepositories:batchCreate -d @requests.json

Replace the following:

  • PROJECT_ID is your Google Cloud project ID.
  • REGION is the region where your GitLab Enterprise Edition configuration is located.
  • GITLAB_ENTERPRISE_EDITION_CONFIG_NAME is the name of your GitLab Enterprise Edition configuration.

What's next