Maven - jenkins pipeline not using pom - maven

I have a problem running a maven deploy through Jenkins. When run locally, the correct URL is contacted, but via Jenkins(in the middle of a pipeline), it does not. It also states that it is using a different plugin to do so. How do I get Jenkins to contact MY_URL like my command line does?
(I've cleaned up the output a bit)
Running the following through the command line gives me:
mvn clean deploy -DaltDeploymentRepository=nexus::default::https://MY_URL/ -DskipTests -P nexus -X -s ./settings.xml
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MY_PROJECT: Failed to deploy artifacts: Could not transfer artifact from/to nexus (https://MY_URL): Failed to transfer file 20200217.092316-15.jar with status code 401 -> [Help 1]
This is what I want (I'm waiting on credentials - but it is hitting the correct URL)
Running via Jenkins gives me:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy (default-deploy) on project : Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
I have done a "diff" on the pom files in use by jenkins and locally and they are identical; likewise with the settings.xml I suspect this is a plugin problem but do not know where to go with it.
Items I have tried:
mvn clean beforehand
reinstalling mvn
echoing the settings.xml and pom.xml into the jenkins output
Specifying altDeploymentRepository in the settings.xml and/or
commandline
Specifying altDeploymentRepository using the -Dproperties= flag
Combinations of altDeploymentRepository, altDeploymentDirectory,
altSnapshotDeploymentRepository
Endless research
Hopeful reruns
Banging head on desk

Your Jenkins runs the org.sonatype.plugins:nexus-staging-maven-plugin:1.5.1:deploy goal.
It is either specified in the POM or given on command line. So first of all, check whether the nexus-staging-maven-plugin is configured in your POM or in one of the parent POMs. If so, check if it run conditionally or is part of a profile.
Secondly, look at the command line call in Jenkins and see if it is exactly the same as the one you ran locally.
The third possibility is that you run a Jenkins plugin from Sonatype that implicitly tries to deploy artifacts. So watch out for Sonatype specific Jenkins plugins.
One of the three strategies should lead to the source of the problem.

Related

Why add a distribution management in POM if Jenkins already knows about it

Pretty much what the title say.
I am trying to build a CI/CD for WSO2. While following this tutorial:
https://docs.wso2.com/display/IntegrationCloud/Implement+Continuous+Integration+and+Deployment+with+Jenkins
It don't say anything about adding a DistributionManagement on the POM and it even has a special POM configuration section, but nevertheless, jenkins is throwing a
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7: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]
So, if jenkins already has the repo URL, the branch and the github, and the POM has a deploy goal that should deploy to a URL:
1) why do I need the Distribution Management?
2) Can I point it to any location like my file system or do I have to point it to the cloud I actually want to deploy to?
according to maven documentation you can upload your build artifact directly to a server with maven using the tag distributionManagement
https://maven.apache.org/pom.html
the important part is the url tag. you can use scp or sftp (maybe other protocols)
scp://user:password#serverUrl/var/some/directory
I would recommend to test locally the command deploy and when you are sure it works, use jenkins.
If you want to make a state of the art jenkins job, I would recommend to use jenkins pipeline, execute maven with sh command and publish to a server using ssh steps provided by ssh-steps-plugin

Maven Build gets Failed saying Could not assemble p2 repository: Mirroring failed: No repository found at

I have a maven build for building an eclipse plugin which gets hung sporadically during the execution of
--- tycho-p2-repository-plugin:1.1.0:assemble-repository (default-assemble-repository) # com.sample.product ---
Otherwise the build will get failed saying the following error.
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-repository-plugin:1.1.0:assemble-repository (default-assemble-repository) on project p2:Could not assemble p2 repository: Mirroring failed: No repository found at file:/C:/Users/obuli/.m2/repository/.
I am using the following maven goals and options
clean deploy -Dtycho.localArtifacts=ignore
I have searched for this issue and landed on this Bug , It says there was a bug in tycho 0.26.0 But I am currently using Tycho version 1.1.0
Since the issue is very sporadic I could not able to identify the root cause. Please let me what I am missing here.
I intermittently had this problem as well. After running mvn clean and mvn deploy separately once, mvn clean deploy started working as well.
Now I don't seem to be able to recreate the original issue, even using git clean -xfd and deleting all snapshots from the local and remote repository.
I can only guess that there were some leftover files from earlier builds which were not cleaned by mvn clean deploy but by mvn clean, and these leftover files must have broken the build.

Jenkins maven projects ignore "Goals and options" specified in project "Build" section

The versions of my system are the following:
Jenkins ver. 1.633
Ubuntu version 14.04.2 LTS
Maven version 3.0.5
I have configured the Maven settings under "Manage Jenkins"-->"Configure system".
When I create an "Invoke top-level Maven targets" step in the "Pre Steps" section everything works as expected. In the "Goals" line I can specify "-X", "clean install", etc. and maven picks this Goals up by printing for example :
[DEBUG] Reading global settings from .../settings.xml
[DEBUG] Reading user settings from .../settings.xml
[DEBUG] Using local repository at .../repository
When I set the same goals (for example -X) in the "Goals and options" input field of the "Build section" I get only the following Jenkins console output:
Parsing POMs ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were
encountered while processing the POMs: [FATAL] Non-resolvable parent
POM: Failure to find nl.icscards:ics-build-parent:pom:1.1.8 in
http://repo.maven.apache.org/maven2 was cached in the local
repository, resolution will not be reattempted until the update
interval of central has elapsed or updates are forced and
'parent.relativePath' points at wrong local POM # line 6, column 10
at
org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:364)
at hudson.maven.MavenEmbedder.buildProjects(MavenEmbedder.java:361)
at hudson.maven.MavenEmbedder.readProjects(MavenEmbedder.java:331)
at
hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1301)
at
hudson.maven.MavenModuleSetBuild$PomParser.invoke(MavenModuleSetBuild.java:1098)
at hudson.FilePath.act(FilePath.java:991) at
hudson.FilePath.act(FilePath.java:969) at
hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.parsePoms(MavenModuleSetBuild.java:960)
at
hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:679)
at
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1741) at
hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531) at
hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:408) Finished: FAILURE
What I expect by specifying "-X" is to get some debugging information the same way as I do when invoking "Invoke top-level Maven targets" as a pre build step like I've shown above.
Please also note that everything works as expected as well if I create a "Freestyle project" instead of a "Maven Project" and execute there a shell statement of the form
cd <job_workspace>
mvn -X clean install
Also in this case I can see the expected output.
Any suggestions of what could be wrong in my "Maven project" jenkins configuration?
Thanks in advance for any replies.
Turns out that the problem was that maven could not find the parent pom which is an external dependency to the project.
The strange thing is that a Maven Jenkins project tries to get these dependencies even before maven can print debug information like which settings file it uses on the jenkins console. Therefore it fails, but it is difficult to guess what the issue is. I thought that it couldn't pick up the right repository path or the right settings.xml file.
In my case the issue was that in the parent pom dependency in the repository I have a file
parent.pom.lastUpdated
which contains a line:
http\://<private-VPN-host>/repo/repo-central/.lastUpdated=1439803113007
From the jenkins server I don't have access to the private VPN host and therefore it fails. Removing that file or the above line solves the problem.
The dependency is than correctly picked up and the maven project builds correctly.

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy - Cannot deploy artifacts when Maven is in offline mode

I run project deploy in Maven project and get the problem as below:
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project iris: Cannot deploy artifacts when Maven is in offline mode -> [Help 1]
Could you help me figure out this problem?
Maven is configured in offline mode, that means Maven will not try to connect to any remote repository. Therefore, the maven-deploy-plugin cannot upload your jar.
Offline mode can be configured in two different ways :
launching Maven with the -o flag. Maven is offline only for this execution.
setting the offline attribute to true in the settings.xml file. Maven is offline for all executions.
One of those two options must be enabled in your configuration and you must remove it for maven-deploy-plugin to work.

Maven release:perform not passing settings file to the deploy phase

I'm having an issue where Maven is not passing the settings to the deploy phase when I use the release plugin. I have my settings.xml file in the same folder as my pom.xml. When I run the following command it deploys successfully to the Maven repository.
mvn deploy -s settings.xml
However when I run this command, it fails saying that it doesn't have permissions to deploy to the repository.
mvn release:perform -B -s settings.xml
Here is the error message:
[INFO] [INFO] Error deploying artifact: Failed to transfer file: http://mavenrepo/groupId/artifactId/versionId/artifactId-versionId.pom. Return code is: 401
The only thing I can think that is causing the second to fail is that the release plugin doesn't pass the settings down to the deploy phase. How do I get this to work?
I used to have the MAVEN_OPTS environment variable set to specify my settings.xml file, but since this will run on from TeamCity, that is no longer an option.
I found a bug in the codehaus Jira for this same issue here. It was fixed in maven-release-plugin 2.2.2. As soon as I changed the version number in my pom.xml, it worked fine.

Resources