I have installed Jenkins and Maven separately in my Linux server. Maven is working from prompt. I tested by giving mvn -version and it gave below output:
Apache Maven 3.2.5
Maven home: /data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /data1/setup_files/JDK1.8/jdk1.8.0_151/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "3.8.13-55.1.6.el7uek.x86_64", arch: "amd64", family: "unix"
But from Jenkins when I try to give a maven build from Jenkins with below shell script:
export M2_HOME=/data1/SOA/app/oracle/product/middleware/Oracle_Home/oracle_common/modules/org.apache.maven_3.2.5
export PATH=$PATH:$M2_HOME/bin
echo "Java Version"
java -version
echo "Maven Version"
mvn -version
It throws following error:
+ echo 'Java Version'
Java Version
+ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
+ echo 'Maven Version'
Maven Version
+ mvn -version
/tmp/jenkins6612268406133694375.sh: line 7: mvn: command not found
Build step 'Execute shell' marked build as failure
I gone through several links and blogs, but none of the steps are helping. I have done the following:
In Manage Jenkins --> Configuration --> Environment variables --> set JAVA_HOME, M2_HOME, ORACLE_HOME, PATH
In Manage Jenkins --> Global Tool Configuration --> set JAVA_HOME and MAVEN_HOME to installation directory in server
I also restarted Jenkins and checked, but still same issue.