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"

## Matched source
Source: Stack Overflow question: https://stackoverflow.com/questions/64140813/publishing-to-gitlab-package-registry-with-deploy-tokens
Original query: "Publishing to Gitlab Package Registry with Deploy Tokens"
Key terms: deploy, gitlab, package, publishing, registry, tokens
