Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Maven installation in Jenkins per individual Slave node?

Tags:

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

like image 575
uvsmtid Avatar asked Feb 07 '15 20:02

uvsmtid


People also ask

How will you configure maven in Jenkins?

In the Jenkins dashboard (Home screen), click Manage Jenkins from the left-hand side menu. Then, click on 'Configure System' from the right hand side. In the Configure system screen, scroll down till you see the Maven section and then click on the 'Add Maven' button. Uncheck the 'Install automatically' option.


1 Answers

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

like image 157
Tim Webster Avatar answered Oct 09 '22 04:10

Tim Webster