I am using the latest Jenkins in my environment and going to compile a simple Java application source with Maven. But, before doing that, I checked that Maven is successfully installed, and then verified build process outside of Jenkins: version (mvn -v), compilation (mvn compile) and etc.
If you are unable to run mvn commands from any shell, you need to check your system’s (Windows, in my case) environment variables : Win+Break -> Advanced system settings -> Advanced -> Environment variables : variable PATH must have a value <maven bin folder> and JAVA_HOME must have a path to JAVA SDK (as shown in the picture below) . You can also get that values by using a simple PS one-liner:
Get-ChildItem env:|where-object {$_.Name -like "JAVA*" -or $_.Name -eq "PATH"}|ft -Wrap
If variables are set correctly and Maven works from cmd/PS, you can switch to Jenkins and try to add a new build job (mvn compile). Unfortunately, the following error may appear while compiling an application source:
\Jenkins\workspace\... was unexpected at this time. Build step 'Invoke top-level Maven targets' marked build as failure
To resolve this , carry out the following steps:
- Open Jenkins and go to Manage Jenkins -> Global Tool Configuration
- Press the GIT , unclear Install automatically and provide name (e.g. Default) and path to GIT executable (C:\Program Files\Git\bin\git.exe , for example)
- Scroll down and press the Maven Installations button, check Install Automatically, provide a name (e.g. Maven_Latest), and then choose Install From Apache and 3.3.9 version.
- Go to your project, click on Configure-Build, and choose a name of your new Maven version that we’ve just added (Maven_Latest), and then press Save
- Re-run the build job and verify that it’s successfully completed
The possible reason – there are some issues with Jenkins and Maven 3.5.x, 3.6.x versions. I’ve tried them all and only 3.3.9 version resolved that problem. If you have any comments/suggestions, please share them.
Thank you so much Sir its really working in my case.