Connect to a GitLab repository

This page explains how to connect aGitLab repository to Cloud Build. To learn more about Cloud Build repositories, seeCloud 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.enable permission.Learn how to grant roles.

    Enable the APIs

Connect to a GitLab repository

Console

  1. Open theRepositories page in the Google Cloud console.

    Open the Repositories page

    You see theRepositories page.

  2. At the top of the page, select the2nd gen tab.

  3. In the project selector in the top bar, select your Google Cloud project.

  4. ClickLink repository to link repositories from your connection.

    You see theLink repository panel.

  5. In theLink repository panel, enter the following information:

    1. Connection: Select a connection from the drop-down menu.
    2. Repository: Select a repository to link to your connection.

    3. Repository Name: Enter a name for your repository.

      1. Generated: Select this option for Cloud Build to automaticallygenerated repository names on your behalf for selected repositories.
      2. Manual: Select this option to manually specify names for yourselected repositories.

        If you selectManual, you can modify the names for yourselected repositories in theRepository names section.

  6. ClickLink to link your repository to your connection.

gcloud

To add a GitLab repository to your connection, enter the followingcommand:

gcloudbuildsrepositoriescreateREPO_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 fromConnect to a GitLab host.
  • REGION is theregion for your connection.

You have now linked a repository to your GitLab connection.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.