24

Symptom

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.

Unacceptable Workaround

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.

Question: Why is it global Jenkins config and not Slave-specific one?

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.

Question: How would I configure Maven installation per Slave node?

Setting environment variables like MAVEN_HOME and M2_HOME to the same path for entire system on Slave node didn't work.

Versions

Both Jenkins Master and Slave are Linux hosts. Jenkins version: 1.598

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
uvsmtid
  • 4,187
  • 4
  • 38
  • 64

4 Answers4

21

Assuming you have Java and Maven installed on your slave:

  1. Go to Manage Jenkins -> Manage Nodes
  2. Click configure icon on the node you wish to configure
  3. Scroll down to 'Node Properties' and tick the 'Tool Locations' checkbox
  4. Fill in the options for Java and Maven.

It should now work (even if you have configured a Maven installation on the master).

Tim Webster
  • 684
  • 8
  • 18
10

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

  • Name: my_maven_3.3.9
  • MAVEN_HOME: /usr/share/maven

Additional configurations for other common tools at /configureTools :

Git installations

  • Name: my_git_2.11.0
  • Path to Git executable: /usr/bin/git

JDK installations

  • Name: my_jdk_1.8.0_161
  • JAVA_HOME: /opt/jdk/jdk1.8.0_161
Anonymous User
  • 908
  • 1
  • 9
  • 5
1

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.

giuspen
  • 1,365
  • 3
  • 20
  • 33
  • If I _do NOT add Maven to the Master_, can I still create a Maven job in Jenkins (New Item => Maven project)? This is a special type of job with UI to support maven parameters. – uvsmtid Feb 27 '15 at 12:19
  • no you have to create a freestyle job and call maven targets – giuspen Feb 27 '15 at 12:44
  • 1
    Unfortunately, the "Maven project" type of Jenkins job is the reason of this question. I have already used "Freestyle" jobs and decided to provide the familiar UI features for those who needs them (including Jenkins UI support for Maven Release plugin). I'll vote up for workaround who needs it, but not accept. Shell environment of each Jenkins Slave can be stuffed with all prerequisites to run any script possible. The question is why Jenkins has counter-intuitive configuration of Maven _per Master_, and not _per (potentially different) Slave_, if we still have to configure Maven outside. – uvsmtid Feb 27 '15 at 16:06
-5

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 :)

Chirag Gupta
  • 115
  • 1
  • 7