Maven deploy from Pipeline won't work. 2 days of nothing but HELL!

Forgive my frustration since the issue I am having is so horrible and frustrating. It seams as if no one on the Internet knows how to fix this!!

I am a new user of gitlab. The whole platform looks very promising and so I started using gitlab for my project. My project uses several maven projects and the first project is only a pom.xml file. It is a maven dependency that all my other projects use. So I want to deploy this dependency to the Package registry and then the other maven projects can use it.

For 2 days now I have been trying to get this to work and unfornately all I can say is that Gitlab is absolutely HELL!!!. I create a project and put a pom.xml in it.

In the repositories section I have this:

<repositories>
        <repository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/groups/MYGROUPID/-/packages/maven</url>
        </repository>
    </repositories>
    <distributionManagement>
        <repository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/groups/MYGROUPID/-/packages/maven</url>
        </repository>
        <snapshotRepository>
            <id>gitlab-maven</id>
            <url>https://gitlab.com/api/v4/groups/MYGROUPID/-/packages/maven</url>
        </snapshotRepository>
    </distributionManagement>

I am using the group package registry since I want all my packages in the same spot. I dont want 10 different urls for all my projects. I then create a ci_settings.xml (Why the hell can’t I just upload a settings.xml somewhere in gitlab?) I now have to change my project structure because of gitlabs failings. In the ci_settings.xml I put this:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <servers>
    <server>
      <id>gitlab-maven</id>
      <configuration>
        <httpHeaders>
          <property>
            <name>Deploy-Token</name>
            <value>${env.CI_DEPLOY_TOKEN}</value>
          </property>
        </httpHeaders>
      </configuration>
    </server>
  </servers>
</settings>

My .gitlab_ci.yml looks like this:

image: maven:latest

variables:
  MAVEN_CLI_OPTS: "-s ci_settings.xml"
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

cache:
  paths:
    - .m2/repository/

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS compile

deploy:
  stage: deploy
  script:
    - mvn $MAVEN_CLI_OPTS deploy
  only:
    - master

And then I check it all in. The pipeline runs and it doesnt work because the Deploy token is missing. I generate a group deploy token and it gives me a username and password. The deploy token in ci_settings.xml has 1 variable. The group token has 2 fields (username/Password). What do I need to fill in there???

Is thiseven the right approach? Gitlab is turning into the biggest disaster I have ever used.

This is the error I see in the log:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project dependencies: Failed to deploy artifacts: Could not find artifact com.project:dependencies:pom:1.0-20210107.111616-1 in gitlab-maven (https://gitlab.com/api/v4/MYGROUPID/10530474/-/packages/maven) -> [Help 1]

Hi @cybergen007 , any luck so far?
I’m facing a similar issue over here and I’m still unable to deploy artifacts to a group-level repo.
Project-level repo deploys work fine though.

Same issue here. Also tried many things. No luck at all.

Hi @devorgint , I also tried a number of combinations (deploy tokens, private tokens, alternative URLs…) and no luck at all.

It seems to be some kind of API issue, since the result of calling the URL

https://gitlab.com/api/v4/groups/xxxxxxxx/-/packages/maven

is a

{"error":"404 Not Found"}

, while calling

https://gitlab.com/api/v4/projects/xxxxxxxx/packages/maven

results in

{"error":"package_id is invalid"}

guys i have found a solution for this, i have disabled the button limit token access under settings → ci/cd → token access on my package registry project and on the project that im using to work on and the pipelines worked perfectly, i have the same configuration that @cybergen007 uses on his files