Build repositories from GitLab Enterprise Edition

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

Cloud Build enables you to create triggers to build from repositories hosted on GitLab Enterprise Edition, allowing you to execute builds in response to events such as commit pushes or pull requests associated with your GitLab Enterprise Edition repository.

This page explains how you can enable trigger functionality on a GitLab Enterprise Edition instance. If you want to build repositories from GitLab, see Building repositories from GitLab.

Before you begin

  • Enable the Cloud Build and Secret Manager APIs.

    Enable the APIs

Creating a GitLab Enterprise Edition trigger

Console

To create a GitLab Enterprise Edition trigger using the Google Cloud console:

  1. Open the Triggers page:

    Open the Triggers page

  2. Select your Google Cloud project from the top of the page and click Open.

  3. Click Create trigger.

  4. Enter the following trigger settings:

    • Name: A name for your trigger.

    • Region: Select the region for your trigger.

      • If you select global as the region, Cloud Build uses the default pool to run your build.
      • If you select a non-global region and the build config file associated with the trigger specifies a private pool, Cloud Build uses the private pool to run your build. In this case, the region you specify in your trigger must match the region where you created your private pool.
      • If you select a non-global region and the build config file associated with the trigger does not specify a private pool, Cloud Build uses the default pool to run your build in the same region as your trigger.
    • Description (Optional): A description for your trigger.

    • Event: Select the repository event to invoke your trigger.

      • Push to a branch: Set your trigger to start a build on commits to a particular branch.

      • Push new tag: Set your trigger to start a build on commits that contain a particular tag.

      • Pull request (Cloud Source Repositories not supported): Set your trigger to start a build on commits to a pull request.

    • Source: Select the repository to build when the GitLab Enterprise Edition trigger runs.

    • Revision: Select the branch or tag to build when the GitLab Enterprise Edition trigger runs.

    • Branch: Set a trigger to build this branch.

    • Tag: Set a trigger to build this tag.

    • Configuration: Select the build config file located in your repository or configure your build inline on the trigger.

    • Type: Select the type of configuration to use for your build.

      • Cloud Build configuration file (yaml or json): Use a build config file for your configuration.
      • Dockerfile: Use a Dockerfile for your configuration.
    • Location: Specify the location for your configuration.

      • Repository: If your config file is located in your repository, provide the location of your build config file or the Dockerfile directory and a name for the resulting image. If your configuration is a Dockerfile, you can optionally provide a timeout for your build. When you've provided the Dockerfile and image name, you'll see a preview of the docker build command that your build will execute.

      • Inline: If you selected Cloud Build configuration file (yaml or json) as your configuration option, you can specify your build config inline. Click Open Editor to write your build config file in the Google Cloud console using YAML or JSON syntax. Click Done to save your build config.

  5. Click Create to create your GitLab Enterprise Edition trigger.

gcloud

To create a GitLab Enterprise Edition trigger using gcloud commands, you need to run the following gcloud alpha builds triggers create gitlab-enterprise command in your terminal:

gcloud alpha builds triggers create gitlab-enterprise
    --name=TRIGGER_NAME \
    --project-namespace=GITLAB_ENTERPRISE_EDITION_PROJECT_NAMESPACE \
    --gitlab-config-resource=projects/PROJECT_NUMBER/locations/REGION/gitLabConfigs/GITLAB_ENTERPRISE_EDITION_CONFIG_NAME \
    --branch-pattern=BRANCH_NAME \ # --tag-pattern=TAG_NAME
    --build-config=BUILD_CONFIG

Replace the following:

  • TRIGGER_NAME is the name of your trigger.
  • GITLAB_ENTERPRISE_EDITION_PROJECT_NAMESPACE the namespace of your GitLab Enterprise Edition project.
  • PROJECT_NUMBER is the project number of your Google Cloud project.
  • REGION is the region where your GitLab Enterprise Edition configuration is located.
  • GITLAB_ENTERPRISE_EDITION_CONFIG_NAME is the name of your GitLab Enterprise configuration.
  • BRANCH_NAME is the regex of your branch if you want to set your trigger to build certain branches.
  • TAG_NAME is the regex of your tag if you want to set your trigger to build certain tags.
  • BUILD_CONFIG is the path to your build config file.

API

To create a GitLab Enterprise Edition trigger with the API, use the following JSON template.

    {
      "filename": "cloudbuild.yaml",
      "name": "curl-trigger",
      "description": "curl trigger",
      "gitlabEnterpriseEventsConfig": {
          "projectNamespace": GITLAB_ENTERPRISE_EDITION_PROJECT_NAMESPACE,
          "push": {
             "branch": BRANCH_NAME # "tag": TAG_NAME
          },
          "gitlabConfigResource": "projects/PROJECT_ID/locations/REGION/gitLabConfigs/GITLAB_ENTERPRISE_EDITION_CONFIG_NAME"
      }
  }

Replace the following:

  • GITLAB_ENTERPRISE_EDITION_PROJECT_NAMESPACE the namespace of your GitLab Enterprise Edition project.
  • BRANCH_NAME is the regex of your branch if you want to set your trigger to build certain branches.
  • TAG_NAME is the regex of your tag if you want to set
  • 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 configuration.

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" https://cloudbuild.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/triggers -d @trigger.json

Replace the following:

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

Data sharing

The data sent to GitLab Enterprise Edition from Cloud Build helps you identify triggers by name and see build results on your GitLab Enterprise Edition repositories.

The following data is currently shared between Cloud Build and GitLab Enterprise Edition:

  • Cloud project ID
  • Trigger name

What's next