Skip to main content

GitLab integration

This documentation explains how to configure the Harbor integration available in GitLab. This integration allows you to use Harbor as a container registry for your GitLab projects.

Create a robot account in Harbor

To allow GitLab to connect to Harbor, you must create a dedicated robot account for it.

info

Robot accounts cannot connect to the Harbor interface.

Create a robot account - Basic informationCreate a robot account - Basic information

This account must have the following permissions:

  • Artifact : List
  • Repository: List, Pull, Push
  • Tag: List
tip

The List permissions allow GitLab to view the Harbor registry.

Create a robot account - Select permissionsCreate a robot account - Select permissions

Once the account has been created, note the following information:

  • The robot account name (in the format <prefix><project_name>+<account_name>)
  • The robot account secret
  • The Harbor project name
  • The URL of your Harbor

Configure Harbor integration in GitLab

In GitLab, integration can be configured at the group or project level.

info

The integration configuration made at the project level replaces the one made at the group level.

It is configured as follows:

  1. From your group or project, go to Settings > Integrations
  2. Select Harbor
  3. Fill in the configuration information:
    • Harbor URL: the URL of your Harbor instance
    • Harbor project name: the name of your Harbor project
    • Harbor username: the name of the Harbor account
    • Harbor password: the user's password
  4. Click Save changes
Configure Harbor integration in GitLabConfigure Harbor integration in GitLab

Using Harbor variables in GitLab CI

Once Harbor integration is enabled, the global variables $HARBOR_USERNAME, $HARBOR_HOST, $HARBOR_OCI, $HARBOR_PASSWORD, $HARBOR_URL, and $HARBOR_PROJECT will be created for use in CI/CD.

Below is an example of how to use these variables in a Docker image build job with Buildah.

.gitlab-ci.yml
build-with-buildah:
stage: build
image: quay.io/buildah/stable:latest
before_script:
- echo "$HARBOR_PASSWORD" | buildah login --username "$HARBOR_USERNAME" --password-stdin $HARBOR_HOST
script:
- buildah build --tag $HARBOR_HOST/$HARBOR_PROJECT/$CI_PROJECT_NAME:latest .
- buildah push $HARBOR_HOST/$HARBOR_PROJECT/$CI_PROJECT_NAME:latest
after_script:
- buildah logout $HARBOR_HOST

View the Harbor registry in GitLab

You can view the Harbor container registry for a project or group.

  1. Navigate to your project or group
  2. Go to Deployment > Harbor Registry

You can search, sort, and filter images on this page.

View the Harbor registry in GitLabView the Harbor registry in GitLab

Source

This documentation is based on the following documentation: