This page explains how to connect a GitLab 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 GitLab host before connecting repositories.
Connect to a GitLab repository
Console
-
Open the Repositoriespage in the Google Cloud console.
You see the Repositoriespage.
-
At the top of the page, select the 2nd gentab.
-
In the project selector in the top bar, select your Google Cloud project.
-
Click Link repositoryto link repositories from your connection.
You see the Link repositorypanel.
-
In the Link repositorypanel, 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.
gcloud
To add a GitLab 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 GitLab repository.
- CONNECTION_NAME is the name given to the GitLab connection created in Cloud Build from Connect to a GitLab host .
- REGION is the region for your connection.
You have now linked a repository to your GitLab connection.
What's next
- Learn how to build repositories from GitLab .
- Learn how to build and deploy your workloads to Google Cloud using Google-managed CI/CD components in your GitLab pipeline. See GitLab on Google Cloud .

