Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>
When Jenkins is used in Linux, the sh 'MVN -- version'
command is added to Jenkins file, but Jenkins reports an error: MVN: command not found
After careful inspection, I found the cause of the problem. The environment variable of the path to Java or Maven is placed in/etc/profile, and/etc/profile is only loaded when the user logs in. Jenkins uses the non login method when running the command, and this method will not be loaded when running the command, Therefore, Jenkins can only find the executable file in the current path
Solution:
global variables can be set in Jenkins settings, Jenkins main page – > Manage Jenkins-> Configure System-> In global properties, select the environment variables check box to display a list of variables and fill in the following:
name: JAVA_ HOME value:XXX
name: M2_ HOME value:/usr/cyz/apache-maven-3.6.1
name:PATH+EXTRA
value: $M2_ HOME/bin
Pay attention to the last red mark path + extra
, which means path = extra: $path, that is, expand the current path variable.
after setting, build succeeds
Similar Posts:
- [Solved] JPype Error: FileNotFoundError: [Errno 2] No such file or directory: ‘/usr/lib/jvm’
- [Solved] Jenkins Run python Project Error: “ModuleNotFoundError: No module named ‘xxx‘”
- [Solved] JAVA Run Error: Error: Could not find or load main class
- [Solved] Jenkins Machine install kubelet Error: authentication failed
- [Solved] Mac install maven Error: zsh: command not found: MVN
- Mac ADB prompts command not found
- [Solved] JSCH cannot run JAVA bash:java:Command not found.
- CentOS Error -bash:systemctl:command not found
- Linux use the man command error: Man: command not found [How to Solve]
- About javac error bash: Java: command not found solution