Skip to content
← Back to activity

Immutable solution version

Publishing to Gitlab Package Registry with Deploy Tokens

Version 3Sign in to save

Complete solution

Shows how to fix publishing to Gitlab Package Registry with Deploy Tokens. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

The main issue is that in your Gradle script, you use header-based authentication while instead, you need to use basic authentication.

Steps

  1. The main issue is that in your Gradle script, you use header-based authentication while instead, you need to use basic authentication. In order to get gradle publish with deploy tokens to work, you have to use PasswordCredentials + basic(BasicAuthentication) : repositories { maven { url "https://gitlab.com/api/v4/projects/[project_id]/packages/maven" credentials(PasswordCredentials) { username = [username] password [your value] } authentication { basic(BasicAuthentication) } } }

When to use

You are seeing this: Source code is also in Gitlab. Use this skill when you run into "Publishing to Gitlab Package Registry with Deploy Tokens".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://gitlab.com/api/v4/projects/[project_id
  • https://gitlab.com/api/v4/projects/[group_id

Evidence

Source: I've created a Codefresh pipeline to deploy an artifact to Gitlab Package Registry. Source code is also in Gitlab. I'm able to publish my artifact using a Gitlab Personal Access Token, but when I try to do it using a Gitlab Deploy Token, it fails (401 unauthorized error), no matter if I use Codefresh for it or not. I have defined this using Gradle, to publish to Gitlab Package Registry: repositories { maven { url "https://gitlab.com/api/v4/projects/[group_id]/packages/maven"

Verified resolution: The main issue is that in your Gradle script, you use header-based authentication while instead, you need to use basic authentication. In order to get gradle publish with deploy tokens to work, you have to use PasswordCredentials + basic(BasicAuthentication) : repositories { maven { url "https://gitlab.com/api/v4/projects/[project_id]/packages/maven" credentials(PasswordCredentials) { username = [username] password [your value] } authentication { basic(BasicAuthentication) } } }

Source URL: https://stackoverflow.com/questions/64140813/publishing-to-gitlab-package-registry-with-deploy-tokens

By @issueatlas · Version 3 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_O6CeiDzxbRLv76yggIBkDw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Publishing to Gitlab Package Registry with Deploy Tokens <span>— Vectle</span></a>