user923499
user923499

Reputation: 343

Unable to push maven artifact to gitlab

I am trying to push an artifact from laptop to gitlab artifactory and not able to push because of the following error.

enter image description here

Error details in terminal:

--- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ tech-root ---

[INFO] Uploading to gitlab-maven: https:// https://gitlab.com/api/v4/projects/<project_id>/packages/maven/com/org/tech/root/tech-root/1.3.0/tech-root-1.3.0

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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.7.RELEASE</version>
        <relativePath/>
    </parent>
    <groupId>com.org.tech.root</groupId>
    <artifactId>tech-root</artifactId>
    <version>1.3.0</version>
    <packaging>pom</packaging>
    <name>TECH ROOT</name>

    <scm>
        <connection>
            scm:git:[email protected]:<project_path>.git
        </connection>
        <developerConnection>
            scm:git:[email protected]:<project_path>.git
        </developerConnection>
        <url>
            https://gitlab.com/
            <project_path>
        </url>
        <tag>HEAD</tag>
    </scm>
    <!--  <issueManagement>-->
    <!--    <system>JIRA</system>-->
    <!--    <url>https://adlm.<org>.com/jira/projects/</url>-->
    <!--  </issueManagement>-->

    <distributionManagement>
        <repository>
            <id>gitlab-maven</id>
            <url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
        </repository>
        <snapshotRepository>
            <id>gitlab-maven</id>
            <url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
            <uniqueVersion>false</uniqueVersion>
        </snapshotRepository>
        <!--    <site>-->
        <!--      <id>${maven.distribution-management.site.id}</id>-->
        <!--      <name>${maven.distribution-management.site.name}</name>-->
        <!--      <url>${maven.distribution-management.site.url}</url>-->
        <!--    </site>-->
    </distributionManagement>


    <repositories>
        <repository>
            <id>snapshots</id>
            <url>file://${user.home}/.m2/repository/</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
        <repository>
            <id>gitlab-maven</id>
            <url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>gitlab-maven</id>
            <url>${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/maven</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <modules>
        <module>module-bom</module>
        <module>libs</module>
    </modules>

    <properties>
        <project.scm.id>gitlab</project.scm.id>
        <java.version>1.8</java.version>
    </properties>

</project>

Settings.xml

<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>Job-Token</name>
                        <value>
                            <!--gitlab_token-->
                        </value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
        <server>
            <id>gitlab-maven</id>
            <configuration>
                <httpHeaders>
                    <property>
                        <name>Private-Token</name>
                        <value>
                            <!--gitlab_token-->
                        </value>
                    </property>
                </httpHeaders>
            </configuration>
        </server>
    </servers>

    <profiles>
        <profile>
            <id>maven-https</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository>
                    <id>gitlab-maven</id>
                    <url>https://gitlab.com/api/v4/projects/<project_id>/packages/maven
                    </url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>

                <repository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>gitlab-maven</id>
                    <url>https://gitlab.com/api/v4/projects/<project_id>/packages/maven
                    </url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>central</id>
                    <url>https://repo1.maven.org/maven2</url>
                    <releases>
                        <enabled>true</enabled>
                        <updatePolicy>never</updatePolicy>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>

            </pluginRepositories>

        </profile>
    </profiles>
</settings>

I added gitlab authentication using access token in servers section of settings.xml and get error.

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project tech-root: Failed to deploy artifacts : Could not transfer artifact com.org:tech-root:pom:1.3.0 from/to gitlab-maven : authentication failed for https://gitlab.com/api/v4/projects/<project_id>/packages/maven/com/org/tech-root/1.3.0/tech-root-1.3.0.pom, status: 401 Unauthorized -> [Help 1]

    <server> <id>registry.gitlab.com</id> <username><gitlab_user_id></username> <password><access_token></password> </server>

Upvotes: 0

Views: 280

Answers (1)

user923499
user923499

Reputation: 343

Use gitlab Job-token to publish artifacts in CI pipeline while running on laptop or any machine need to use gitlab Private-Token to pull artifacts from gitlab package registry

Upvotes: 0

Related Questions