Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

maven deploy fails to upload in nexus

Hi Team,

I can able to run the CICD stages(config, package proxy bundle and deploy proxy bundle) which apigee is suggested but when i try to upload the zip file into Nexus which is failing.

A sample snapshot of pom file:

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-deploy-plugin</artifactId>

<version>${plugins.maven.deploy.version}</version>

<executions>

<execution>

<id>default-deploy</id>

<phase>deploy</phase>

<goals>

<goal>deploy</goal>

</goals>

</execution>

</executions>

</plugin>

In Settings.xml we have the following nexus credentials enabled. Also we have provided full access in terms of upload but didn't help.

<servers>

<server>

<id>jenkins-maven-uploads</id>

<username>REDACTED</username>

<password>REDACTED</password>

</server>

</servers>

I'm getting the following error in Jenkins.

23:06:19 Uploading: https://REDACTED/Filename-0.0.1.pom 23:07:06 [INFO] ---------------------------23:07:06

[INFO]

BUILD FAILURE 23:07:06 [INFO] ------------------------------------------------------------------------ 23:07:06 [INFO]

Total time: 55.809 s 23:07:06 [INFO]

Finished at: 2020-06-09T22:07:03+00:00 23:07:06 [INFO]

Final Memory: 25M/356M 23:07:06 [INFO] ------------------------------------------------------------------------

23:07:06 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project REDACTED: Failed to deploy artifacts: Could not transfer artifact REDACTED from/to jenkins-maven-uploads (REDACTED/maven-releases/): Access denied to: https://REDACTED/Filename-0.0.1.pom, ReasonPhrase: Forbidden. -> [Help 1] 23:07:06 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project REDACTED: Failed to deploy artifacts: Could not transfer artifact REDACTED from/to jenkins-maven-uploads (REDACTED/maven-releases/): Access denied to: https://REDACTED/Filename-0.0.1.pom, ReasonPhrase: Forbidden.

Solved Solved
0 9 32.3K
1 ACCEPTED SOLUTION

@Sundar Prince

This will work when you are trying to push a jar file that also generates a pom file. In this case, the artifact is a zip file. So you should use the "deploy:deploy-file" command. Here are the steps

1) Create a server entry in your settings.xml (which you have already done)

2) Add this to your pom file (or parent-pom). Remove the existing maven-deploy-plugin you have

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>3.0.0-M1</version>
    <executions>
        <execution>
            <id>deploy-jar-file</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <file>${basedir}/target/${name}-${version}-${env}.zip</file>
                <url>http://url</url>
                <repositoryId>jenkins-maven-uploads</repositoryId>
                <packaging>zip</packaging>
            </configuration>
        </execution>
    </executions>
</plugin>

Please update the url property

3) If you are calling "mvn install" from your pipeline currently, then change that to "mvn deploy" which will do everything including installl

or

if you want to call the deploy step alone at the very end then try "mvn org.apache.maven.plugins:maven-deploy-plugin@deploy-jar-file" which invokes the "deploy-jar-file" executionid in your pom file.

Let me know how it goes

View solution in original post

9 REPLIES 9