Hudson+Maven+SVN get this FATAL: Couldn't find any executable in D:\Program Files (x86)\Maven\apache-maven-3.3.9 - maven

I build a continuous integration system with Hudson+Maven+ SVN,When I build a job I get this error
While I use maven by command line, it succeed. the configuration of Hudson is below
the environment variable is set well

Hudson can't find the maven executables. You should point the MAVEN_HOME environment variable to the C:\YOUR_PATH_TO_MAVEN_DIRECTORY\bin directory and not to the installation directory itself.

Related

mvn not found when executed via Jenkins shell script

I have set M2_HOME under Manage Jenkins -> configure system -> Environment variables and also under Manage Jenkins -> global tool configuration.
When I use maven project, it is working fine.
But when I use freestyle project and execute shell, it throws an error "mvn not found".
But when I give echo $M2_HOME in Execute shell, it shows the correct path.
Also, when I tried $M2_HOME/mvn compile, it worked fine.
I could not figure out the exact issue.
Error
[Compile]
$ /bin/sh -xe /tmp/jenkins1984982949384007169.sh
+ mvn --version
/tmp/jenkins1984982949384007169.sh: 2: /tmp/jenkins1984982949384007169.sh: mvn: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
The shell which executes the mvn command doesn't know that the path for the script in in the M2_HOME variable. The shell will only look at commands listed in the $PATH variable.
So there are two solutions:
Always use "$M2_HOME/mvn" to execute Maven (or rather "$M2_HOME/bin/mvn" since M2_HOME should point to the folder which contains bin and lib and not to the script itself).
Change the path at the top of the script to make the shell search in the right place:
export PATH="$M2_HOME/bin:$PATH"
That probably only makes sense when you run Maven more than once in the script.

Couldn’t find any executable in apache-maven-3.3.3

I have a windows jenkins slave and I have download apache-maven-3.3.3 on it.
It is located C:\Users\myUsername\Desktop\apache-maven-3.3.3 This is copy and pasted from the windows explorer on my Windows slave.
Then when I point at this location in Jenkins and run a build. I get this error
Couldn’t find any executable in C:\Users\myUsername\Desktop\apache-maven-3.3.3
I have also tried Couldn’t find any executable in C:\Users\myUsername\Desktop\apache-maven-3.3.3\bin
This works just fine on my linux slaves. What is the difference? Why is this not working?
Maven changed the name of the executable in Maven 3.3 from mvn.bat to mvn.cmd. Jenkins recognized mvn.cmd since Jenkins 1.613 (see this commit). If you are on an earlier Jenkins version you can add a symlink from mvn.bat to mvn.cmd on windows as a workaround.
The executable is in the \bin folder (namely, mvn.bat). Try to point Jenkins to C:\Users\myUsername\Desktop\apache-maven-3.3.3\bin
First
Under your Windows machine
1. create an Environment Virable named MAVEN_HOME and set its value to C:\Users\myUsername\Desktop\apache-maven-3.3.3.
2. Add %MAVEN_HOME%\bin into your System PATH
Second
Go to
http://your-jenkins-server/computer/your-windows-slave/configure -->Node Properties-->Tool Locations-->(Maven)maven
and set its value to C:\Users\myUsername\Desktop\apache-maven-3.3.3 as well.
Third
Reconnect your jenkins slave, then rerun your job.
Well for me it was wrong setting for maven. Go to configure, under post build action, go to advanced setting and there fix the Maven version to be used, i changed it to maven 3.3.3 and it worked.
I am using Windows. The accepted answers does not work for me. So, I have to create a new Maven in Jenkins and select the option "Install automatically". Then it works.

Error: M2_HOME is set to an invalid directory

I got this error
Error: M2_HOME is set to an invalid directory.
M2_HOME = "C:/Users/joanet/.m2/repository"
Please set the M2_HOME variable in your environment to match the
location of the Maven installation
but C:/Users/joanet/.m2/repository is a valid directory !
Yes, your folder is valid, but this is not the folder you want to point to.
I think it should point actually where the error messages says to you, to your maven installation folder (something like this)
C:\development\maven\apache-maven-3.1.0
You are currently pointing to your local repository, something which is usually configured in the settings.xml of maven (in the conf folder of the previous url route).
Such issue appears also, if you have 2 or more mavens installed. Try to delete old versions to have only latest.
Check the System Variable M2_HOME and PATH values set in different maven installation locations.
If your java version is 8
you can remove "MAVEN_OPTS : -Xms256m - XMX512m" environmental variable and check "mvn -v".
because java 8 does not support for the above config.
This happened to me when I tried to upgrade to new Maven version.
Below are the steps you should follow when setting up Maven on Windows. If something is missing, the above error will trigger (most probably the 2nd or 3rd step may be missing for mentioned error).
Step 1:
First, download(Apache Maven download link:
https://maven.apache.org) and extract it to C:\Program Files
Step 2:
Go to Environment Variables and Define below varibles in System variables
M2_HOME - C:\Program Files\apache-maven-3.3.9 MAVEN_HOME -
C:\Program Files\apache-maven-3.3.9
Step 3:
Make sure to add the maven bin file to Path varible in System variable
C:\Program Files\apache-maven-3.3.9\bin
Step 4:
Once you are done with configurations, make sure to restart the project.
Step 5:
Check whether the Maven is configured successfully using below command
mvn -version

Maven not recognized in Jenkins

I have installed Tomcat 7 on Windows 8, on which Jenkins is deployed. I configured the JDK, Ant and Maven in the Jenkin settings. In the Maven section, I gave a name as LocalMaven and the MAVEN_HOME as C:\Techie\apache-maven. When I did a test build, it gave me the following error that the mvn.bat is not recognized. Then I checked by entering mvn command in CMD. It gave some maven statements, which means maven is available in the PATH variables.
After googling, I changed the MAVEN_HOME as **%M2_HOME%\bin** in Jenkin-Maven configuration. Still it did not work.
LOG:
[workspace] $ cmd.exe /C '"mvn.bat -f HighScoresServiceClient compile && exit %%ERRORLEVEL%%"'
'mvn.bat' is not recognized as an internal or external command,
operable program or batch file
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
Edited: Added the analysis
The command executed by Jenkins is [workspace] $ cmd.exe /C '"mvn.bat -f String-replacer compile && exit %%ERRORLEVEL%%"' where mvn.bat is not a valid command and so Jenkins errors out as follows that 'mvn.bat' is not recognized as an internal or external command, I think Jenkins should call the command as mvn and not mvn.bat. Can some experts correct me if I am wrong? Please let me know how to change this behaviour if I am right.
Edited: Attached the Configuration
I suppose your Tomcat server is running as a Windows service.
Did you create your MAVEN_HOME and M2_HOME as system environment variables? (idem for your PATH)
Another solution is to configure your variables in the apache-tomcat/bin/setenv.bat file:
set MAVEN_HOME=C:\Techie\apache-maven
set PATH=%MAVEN_HOME%\bin;%PATH%
I bet you've installed Maven 3.3 that has mvn.bat renamed to mvn.cmd
There is a report on this issue in Jenkins JIRA: https://issues.jenkins-ci.org/browse/JENKINS-27525

Jenkins executing maven from incorrect path

This happens for both: maven projects, and freestyle projects, when maven target is envoked, it tries to execute mvn using absolute path.
[MY-Job] $ tools/Maven/Jenkins_Private_Maven/bin/mvn -f cc/pom.xml -Ddeploy_env=xxx.dev.prv -Dbranch=dev -D-Dsmdist.target=/opt/builds -U clean test -DtestGroups=unit,delegate -Do verride:server=xxx.dev.prv
FATAL: command execution failed
java.io.IOException: Cannot run program "tools/Maven/Jenkins_Private_Maven/bin/mvn" (in directory "workspace/MY-Job"): java.io.IOException: error=2, No such file or directory
I can see that mvn is installed at user's home :
/home/jenkins/tools/Maven/Jenkins_Private_Maven/bin/mvn
but it's trying to run it from the workspace:
/home/jenkins/workspace/MY-Job/tools/Maven/Jenkins_Private_Maven/bin/mvn
Add the default maven installation under (Jenkins -> configuration)
Goto the failing job and make sure you choose the default maven installation from dropdown
Run the job. Success!
Are you sure you have set up Maven in Jenkins -> configuration like this
I have hunch you have a accidental **"."** current directory reference somewhere in your maven set up.
This looks like an auto installed Maven by Jenkins. In which case the previous answers are not correct.
It would seem in this occasion that you have not specified a "remote fs root" for your slave in the salve setup - later versions of Jenkins flag not setting this up correctly as an error.
in Jenkins 2.43:
Manage Jenkins -> Global Tool Configuration -> Maven

Resources