CI/CD maven deploy variables

Replace this template with your information

I have a group where there are multiple projects. I am trying to implement CI/CD pipeline to build and deploy SNAPSHOT and release version to repository.
In group I have defined variables calles:

  • ARTIFACT_USER
  • ARTIFACE_PASS

ci_settings.xml:

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <servers>
   <server>
      <id>repo</id>
      <username>${env.ARTIFACT_USER}</username>
      <password>${env.ARTIFACT_PASS}</password>
    </server>
  </servers>
</settings>

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...

  <repositories>
    <repository>
      <id>repo</id>
      <name>repo</name>
      <url>URL</url>
    </repository>
  </repositories>
  <distributionManagement>
    <repository>
      <id>repo</id>
      <name>repo</name>
      <url>URL</url>
    </repository>
  </distributionManagement>
  ...
</project>

gitlab-ci.yml

variables: 
  MAVEN_BUILD_COMMAND: "package -DskipTests=true -s ci_settings.xml"
  ARTIFACT_PATH: target/
  MAVEN_VERSION: 3
  JDK_VERSION: 11

stages:          # List of stages for jobs, and their order of execution
  - build
  - test
  - deploy

.java-mvn:
  image: maven:$MAVEN_VERSION-jdk-$JDK_VERSION
  only:
    - merge_requests
    - master

build-job:       # This job runs in the build stage, which runs first.
  extends: .java-mvn
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS clean $MAVEN_BUILD_COMMAND
  artifacts:
    paths:
      - $ARTIFACT_PATH
    expire_in: 60min

unit-test-job:   # This job runs in the test stage.
  extends: .java-mvn
  stage: test    # It only starts when the job in the build stage completes successfully.
  script:
    - mvn surefire:test -s ci_settings.xml

deploy-job:      # This job runs in the deploy stage.
  extends: .java-mvn
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  script:
    - 'mvn deploy -s ci_settings.xml'
  when: manual

Both of the projects have the same gitlab-ci.yml and ci_settings.xml. Both projects have similar pom.xml and are exactly regarding repositories and distribution management.

The problem is that one is working with CI/CD variables, and another only works if I hard-code username and password inside ci_settings.xml.

I have also tried to add CI/CD variables into projects itself and it is still the same problem.

The response i get is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project common: Failed to retrieve remote metadata GROUP_NAME:ARTIFACT_ID:1.0-SNAPSHOT/maven-metadata.xml: Could not transfer metadata com.aqualife:common:1.0-SNAPSHOT/maven-metadata.xml from/to repo (URL): authentication failed for URL, status: 401 Unauthorized → [Help 1]

Can you help me?