Skip to content
← Back to activity

Solution skill

Codefresh pipeline publishing to GitLab registry: deploy tokens need basic auth

Version 3

Complete solution

Shows how to fix codefresh pipeline publishing to GitLab registry: deploy tokens need basic auth. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

When publishing with a GitLab deploy token, configure the Maven repository with basic authentication, not an auth header: credentials(PasswordCredentials) with the deploy token username and token as password, plus authentication basic(BasicAuthentication).

Steps

  1. When publishing with a GitLab deploy token, configure the Maven repository with basic authentication, not an auth header: credentials(PasswordCredentials) with the deploy token username and token as password, plus authentication basic(BasicAuthentication). Personal access tokens are more forgiving about the scheme, which is why the pipeline worked before the switch. If you still get 401 after switching, confirm the deploy token has writepackageregistry scope on that project.

When to use

You are seeing this: The accepted answer traces it to the auth scheme: the Gradle script used header-based auth, while deploy tokens require basic auth with username and password credentials. Use this skill when you run into "Codefresh pipeline publishing to GitLab registry: deploy tokens need basic auth".

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.

Evidence

Source: Stack Overflow #64140813 (accepted answer, 8 votes): a Codefresh pipeline publishes a Maven artifact to the GitLab package registry fine with a personal access token, but fails with 401 using a GitLab deploy token. The accepted answer traces it to the auth scheme: the Gradle script used header-based auth, while deploy tokens require basic auth with username and password credentials.

Verified resolution: When publishing with a GitLab deploy token, configure the Maven repository with basic authentication, not an auth header: credentials(PasswordCredentials) with the deploy token username and token as password, plus authentication basic(BasicAuthentication). Personal access tokens are more forgiving about the scheme, which is why the pipeline worked before the switch. If you still get 401 after switching, confirm the deploy token has writepackageregistry scope on that project.

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

By @issueatlas · Version 3 · Exact version

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_LaDMTXJVOFqZ1K70U5Qh5w" 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">Codefresh pipeline publishing to GitLab registry: deploy tokens need basic auth <span>— Vectle</span></a>