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 28.9K
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

@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

Thanks for the detailed steps Sai. I have removed the existing maven deploy plugin and added the above plugin which didn't work as expected. I'm not sure whether i'm missing any dependencies. I have also updated the right URL and file but it doesn't work.

12:16:29 + mvn deploy

12:16:31 [INFO] Scanning for projects... 12:16:31 [INFO] 12:16:31 [INFO] ------------------------------------------------------------------------ 12:16:31 [INFO] Building ipgapiproxy 0.0.1 12:16:31 [INFO] ------------------------------------------------------------------------ 12:16:31 Downloading: https://REDACTED/repository/repocentral/org/apache/maven/plugins/maven-deploy-plugin/3.0.0-M1/maven-... 12:16:33 [INFO] ------------------------------------------------------------------------ 12:16:33 [INFO] BUILD FAILURE 12:16:33 [INFO] ------------------------------------------------------------------------ 12:16:33 [INFO] Total time: 2.616 s 12:16:33 [INFO] Finished at: 2020-06-15T11:16:33+00:00 12:16:33 [INFO] Final Memory: 10M/150M 12:16:33 [INFO] ------------------------------------------------------------------------ 12:16:33 [ERROR] Plugin org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:3.0.0-M1: Could not transfer artifact org.apache.maven.plugins:maven-deploy-plugin:pom:3.0.0-M1 from/to nexus (https://REDACTED/repository/repocentral): Access denied to: https://REDACTED/repository/repocentral/org/apache/maven/plugins/maven-deploy-plugin/3.0.0-M1/maven-... , ReasonPhrase:Forbidden. -> [Help 1]

15:34:25 + mvn deploy:deployfile -Dfile=/Path to the file/filename.zip

15:34:27 [INFO] Scanning for projects... 15:34:28 Downloading: REDACTED/repository/repocentral/org/apache/maven/plugins/maven-deploy-plugin/3.0.0-M1/maven-deploy-plugin-3.0.0-M1.pom 15:34:32 [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1: Plugin org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:3.0.0-M1 15:34:32 [WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1: Plugin org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:3.0.0-M1

@Sundar Prince - Can you try it locally ? I still see "Forbidden" which means there is a permission issue. Please check that out

Even though i had highest privileges from Nexus to my svc account. I was still unable to upload the zip file. I have also added dependency management in the pom file and I have modified my maven command for a successful artifact upload into nexus.

mvn deploy:deploy-file -DgroupId=groupid -DartifactId=artifact id -Dversion=version -DgeneratePom=true -Dpackaging=zip -DrepositoryId=serverid -Durl=NexusURL/maven-releases -Dfile=${WORKSPACE}/target/Filename.zip

Try running it with -X and see what error you are seeing. Make sure you are passing the correct serverId that you have configured in your settings.xml. Make sure the username password fields are accurate.

If possible - login to your Nexus repo and try uploading the zip using the UI itself. Worst case - see if they have an API to push it. If they do, then you can probably include a curl command in your pipeline to push it to Nexus

I was saying that above maven command made the trick and i was able to upload the artifacts into Nexus. Thanks for your help

Oh awesome ! Thats great news. Can you please accept the answer here

Hi Sai,

I dont have option to try it on my local rather i tried it on my personal ec2 instance.

This is the executions i have set in pom file. Though i dont have any nexus to check on my own. I have just set as repo.maven.

P.S: I took the repo ID from settings.xml

<execution>

<id>deploy-jar-file</id>

<phase>deploy</phase>

<goals>

<goal>deploy-file</goal>

</goals>

<configuration>

<file>${basedir}/target/HelloWorld-1.0-test.zip</file> <url>https://repo.maven.apache.org</url>

<repositoryId>deploymentRepo</repositoryId>

<packaging>zip</packaging>

</configuration>

</execution>

I get the below error when i run the mvn deploy or mvn deploy:deploy file. Since i'm testing it on my personal ec2 instance i don't have a proper nexus or repository id to check it here...

[root@ip-REDACTED HelloWorld]# mvn deploy:deploy-file -Dfile=/Filepath/filename.zip -e -X Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

[DEBUG] -- end configuration -- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.067 s [INFO] Finished at: 2020-06-16T15:53:43Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file (default-cli) on project HelloWorld: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file are missing or invalid -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file (default-cli) on project HelloWorld: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file are missing or invalid at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)

[root@ip-REDACTED HelloWorld]# mvn deploy -Ptest [INFO] Deployed revision is:7 [INFO] [INFO] --- maven-deploy-plugin:3.0.0-M1:deploy (default-deploy) @ HelloWorld --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 14.665 s [INFO] Finished at: 2020-06-16T15:48:08Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy (default-deploy) on project HelloWorld: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

@Sundar Prince - you cannot deploy that to the repo you provided. Thats the central maven repository. You should have your own repo provided to push your custom artifacts. Please provide that