1

First I installed Maven version 3.0.5 on our build system and then I upgraded it to 3.6.0 following this guide https://linuxize.com/post/how-to-install-apache-maven-on-centos-7/ . Using the cmdline on the system executing:

mvn -v

I always get 3.6.0 as the version. But when executing the same command in a Jenkins job I get 3.0.5 . So somewhere it looks like it still refers to the older version. But I have no clue where. Any ideas how to check this?

Nicholas
  • 1,189
  • 4
  • 20
  • 40

1 Answers1

2

The version you see in the shell depends on your PATH variable.

Jenkins can handle multiple installations of maven. To configure it:

  • Open the Jenkins dashboard.
  • Go to Manage Jenkins.
  • Go to Global Tool Configuration
  • Go to the Maven section and click Maven installations

When adding a new installation, you have 2 options:

  • install a selected version automatically
  • use existing installation on your system

Then, when configuring a project in jenkins, you can select one of the configured installations.

  • For Maven Project under Build / Maven Version
  • For Freestyle project under Build Steps / Build / Invoke top level maven targets / Maven Version
Lesiak
  • 22,088
  • 2
  • 41
  • 65
  • Is there a way to make Jenkins just use the Maven as the PATH variable? I would like to use mvn in a Freestyle Project instead of a Maven project – Nicholas Jun 04 '19 at 14:48
  • Updated my answer, you can use any existing installation from your system (but I think you must be explicit and point it to the correct directory) – Lesiak Jun 04 '19 at 14:57
  • I was able to proceed thanks to your answer but I have another issue now. I noticed that when I'm logged in to the system as the jenkins user and I perform 'sudo mvn -v' I get a different version compared to when executing without sudo. How can I make this sudo jenkins user also make use of mvn 3.6.0 instead of 3.0.5? – Nicholas Jun 05 '19 at 08:52
  • Sudo changes PATH on many distributions. https://stackoverflow.com/questions/257616/why-does-sudo-change-the-path – Lesiak Jun 05 '19 at 09:29
  • I did not try your last comment but I just found a workaround which also works out fine for me. As with sudo it used /usr/share/maven and I wanted to use /opt/maven I now just use following command 'sudo /opt/maven/bin/mvn' to execute maven. This works fine and uses sudo + v3.6.0 . – Nicholas Jun 05 '19 at 09:31