Reputation: 4295
If I create a Maven job in Jenkins (New Item => Maven project, using the maven plugin) with all defaults and run it, I get this error:
Started by user anonymous
Building on master in workspace /var/lib/jenkins/jobs/job_name/workspace
ERROR: A Maven installation needs to be available for this project to be built.Either your server has no Maven installations defined, or the requested Maven version does not exist.
Finished: FAILURE
Maven runs perfectly from command line with just mvn
.
There is a system-wide Jenkins configuration for Maven installation: Manage Jenkins => Configure System => Maven / Maven installations. And if I add Maven installation using this web UI (by providing pre-installed path in MAVEN_HOME
as /usr/share/maven
), the job runs SUCCESSFULLY.
The global Jenkins config does not make sense: Maven is run per Slave, not per Jenkins.
The zoo of Slaves where Jenkins runs jobs may contain Slaves with various platforms, OSes, environments where different versions of Maven are installed in different locations.
Setting environment variables like MAVEN_HOME
and M2_HOME
to the same path for entire system on Slave node didn't work.
Both Jenkins Master and Slave are Linux hosts. Jenkins version: 1.598
Upvotes: 24
Views: 93513
Reputation: 115
To make it simple, just use my public docker image
docker push chiraggupta95/jenkinswithmvn:v1
In case you want to customize your own image, just check out my git repo for complete instructions.
https://github.com/chiraggupta95apr/jenkins
Happy Coding :)
Upvotes: -5
Reputation: 928
For me, the solution was to go to Manage Jenkins -> Global Tool Configuration, and set up maven there. You can access this via /configureTools (ex: http://your-ip:8080/jenkins/configureTools )
Example: Maven installations
Additional configurations for other common tools at /configureTools :
Git installations
JDK installations
Upvotes: 11
Reputation: 734
Assuming you have Java and Maven installed on your slave:
It should now work (even if you have configured a Maven installation on the master).
Upvotes: 23
Reputation: 1401
If you do NOT add Maven to the Master configuration and you just install it on every slave with their own possibly different environment variables (example with version 3.2.5)
M2_HOME=C:\apache-maven-3.2.5
M2=C:\apache-maven-3.2.5\bin
Path+=;C:\apache-maven-3.2.5\bin
then every Jenkins slave will just use Maven with local settings.
Upvotes: 1