"mvn: not found" in Jenkins slave

12,141

Solution 1

run mvn --version locally to get Mavan home path

[[email protected]]# mvn --version

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)mvn --version
Maven home: /opt/apache-maven-3.3.9
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/jdk1.8.0_131/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.18.2.el7.x86_64", arch: "amd64", family: "unix"

then add the following to Execute shell prior to running any mvn command. That'll do it.

export M2_HOME=/opt/apache-maven-3.3.9 # your Mavan home path
export PATH=$PATH:$M2_HOME/bin
mvn --version

Solution 2

I found a solution: You just have to set proper Environment variable in node configuration like in the picture below. enter image description here

Share:
12,141
M. Stefanczuk
Author by

M. Stefanczuk

Updated on June 25, 2022

Comments

  • M. Stefanczuk
    M. Stefanczuk almost 2 years

    I have Jenkins slave with Java and Maven installed (environment is Debian). I can run "java -version" and "mvn -version" commands in console.

    But when I try to execute shell commands in Jenkins job, then I get "mvn: not found" error. Java command works fine.

    jenkins shell

    Can you tell me what should I do to be able to run shell "mvn" command on slave?

  • Juan Rojas
    Juan Rojas over 5 years
    Thanks. It worked for me on CentOS 7 and Freestyle Project on Jenkins
  • Sameera De Silva
    Sameera De Silva about 3 years
    Thank you Serhii Aksiutin , you are a life saver. I was trying to create a fre style project in docker and your anwer helped.