Home > Software engineering >  "mvn: command not found" in jenkins job install binary even after setting environment vari
"mvn: command not found" in jenkins job install binary even after setting environment vari

Time:01-12

I created a freestyle jenkins job.

I am getting following error.

"mvn: command not found" on jenkins jobs when I install maven using binary but runs successfully when I install maven using "yum install maven"

I have installed maven using binary installation and set up environment variable into .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

export M2_HOME=/opt/maven

export M2=$M2_HOME/bin

export PATH=$M2:$PATH

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

I am able to find version on terminal.

[ec2-user@ip-172-31-93-112 ~]$ mvn -v
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /opt/maven
Java version: 11.0.17, vendor: Amazon.com Inc., runtime: /usr/lib/jvm/java-11-amazon-corretto.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.10.157-139.675.amzn2.x86_64", arch: "amd64", family: "unix"

But when I am running jenkins job I am getting error "mvn: command not found"

When I installed maven using "yum install maven" same jenkins job running successfully.

I just wanted to know how do the same when we installed maven using binary.

CodePudding user response:

I resolved this error by adding maven environment variables inside jenkins freestyle job > Build Steps > Execute shell

export M2_HOME=/opt/maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
mvn clean
mvn install

It is now working as expected.

  • Related