Tag Archives: Jenkins – mvn: command not found

Jenkins – mvn: command not found

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+EXTRAvalue: $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