Skip to content
← Back to activity

Immutable solution version

Publishing to Gitlab Package Registry with Deploy Tokens

Version 1Sign in to save

Complete solution

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

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) } } }

Context: 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"

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 1 · 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>