Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven not found in Jenkins

I am running my Maven/Spring project in Jenkins (just testing it out, first time) using the shell script option with:

mvn spring-boot:run

I get the build error: /Users/Shared/Jenkins/tmp/jenkins8087926087546049217.sh: line 2: mvn: command not found

How can I fix this? Its a Spring-boot app. It works fine when I run mvn spring-boot:run via command line.

like image 727
Charo Avatar asked Aug 19 '17 23:08

Charo


4 Answers

"Manage Jenkins"->"Global Tool Configuration" enter image description here

if still not work, add the following to "Execute shell"

export MAVEN_HOME=/opt/maven
export PATH=$PATH:$MAVEN_HOME/bin
mvn --version
mvn clean package

enter image description here

like image 113
LIU YUE Avatar answered Oct 23 '22 03:10

LIU YUE


export MAVEN_HOME=/opt/maven
export PATH=$PATH:$MAVEN_HOME/bin
mvn --version
mvn clean package

and then mvn install

like image 29
mushroom_lb Avatar answered Oct 23 '22 02:10

mushroom_lb


I also met the problem and solved it. I think you may be using a "FreeStyle Project" instead of a "Maven Project" when you creating a new project via "New Item" button.

In FreeStyle Project, Jenkins may not read environment variables in Linux server and the Maven installations in "Global Tool Configuration", so I configured environment variables repeatedly in "Configure System". Then it worked.

like image 23
hackeryang Avatar answered Oct 23 '22 03:10

hackeryang


Try this, Navigate to Manage Jenkins and click on Global Tool Configuration, In Maven section click on the 'Add Maven' button and provide the maven installation path in MAVEN_HOME and save configurations.

Maven config in Jenkins

like image 43
Anil Kumar Athuluri Avatar answered Oct 23 '22 01:10

Anil Kumar Athuluri