GitLab CE Group Maven Package Registry

We’ve been publishing to GitLab’s maven repository from Gradle for about 2 years now. It was very tricky to get it working, but it does work.

The two biggest gotchas we ran into:

  • You need to use a different HTTP header for $CI_JOB_TOKEN vs personal access token (PAT) authentication. Use Job-Token for CI_JOB_TOKEN, Private-Token for PAT.
  • You can pull packages from the group or project level, but publishing only works at the project level. The group level is essentially an aggregated view of all projects in the group.

Also, GitLab’s API loves to give misleading error messages if you don’t have access to do something. The 415 doesn’t sound familiar to me, but I wouldn’t be surprised if the media type is a red herring.

The fact that the URL in OP’s error message starts with “https://gitlab.com/api/v4/groups/” suggests to me they’re trying to publish at the group level. The publish URL needs to be “https://gitlab.com/api/v4/projects/${System.getenv(‘CI_PROJECT_ID’)}/packages/maven” (note “/v4/projects/”, not “/v4/groups/”)

1 Like