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 write_package_registry scope on that project.

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