This page explains how to connect a GitLab Enterprise Edition repository to Cloud Build.
Before you begin
-
Enable the Cloud Build and Secret Manager APIs.
- Follow the instructions to connect a GitLab Enterprise Edition host before connecting repositories.
Connecting to a GitLab Enterprise Edition repository
Console
To connect a GitLab Enterprise Edition repository to Cloud Build using the Google Cloud console:
Open the Triggers page in the Google Cloud console.
Click Connect Repository.
The Connect repository panel appears.
Under Select source, select GitLab Enterprise Edition.
Under Select Repository, select the GitLab Enterprise Edition repositories you wish to connect to Cloud Build.
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
gcloud alpha builds enterprise-config gitlab describe CONFIG_NAME --region=REGION
Where:
- CONFIG_NAME is the name of the GitLab Enterprise Edition config
- REGION is the region of the GitLab Host connection
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
- Learn how to build repositories from GitLab Enterprise Edition.
- Learn how to build repositories from GitLab Enterprise Edition in a private network.
- Learn how to perform blue/green deployments on Compute Engine.