[英]"mvn: command not found" in jenkins job install binary even after setting environment variable properly able to find version "mvn -v" on terminal
I created a freestyle jenkins job.我创建了一个自由式 jenkins 工作。
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"当我使用二进制安装 maven 时,在 jenkins 作业上出现“mvn: command not found”,但当我使用“yum install maven”安装 maven 时运行成功
I have installed maven using binary installation and set up environment variable into.bash_profile我已经使用二进制安装安装了 maven 并将环境变量设置为.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"但是当我运行 jenkins 作业时,出现错误“mvn: command not found”
When I installed maven using "yum install maven" same jenkins job running successfully.当我使用“yum install maven”安装 maven 时,相同的 jenkins 作业成功运行。
I just wanted to know how do the same when we installed maven using binary.我只是想知道当我们使用二进制安装 maven 时如何做同样的事情。
I resolved this error by adding maven environment variables inside jenkins freestyle job > Build Steps > Execute shell我通过在 jenkins freestyle job > Build Steps > Execute shell 中添加 maven 环境变量解决了这个错误
export M2_HOME=/opt/maven
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
mvn clean
mvn install
It is now working as expected.它现在按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.