Issue
My test is working fine as Maven project. It fetches code from Git.
I wanted to execute the same in Pipeline so I wrote the below script for pipeline project.
pipeline {
agent any
options {
timestamps()
}
stages{
stage('Just Testing') {
steps {
git "https://github.com/myRepo.git"
script{
sh 'mvn test'
}
step([$class : 'Publisher', reportFilenamePattern : "**/testng-results.xml"])
}
}
}
}
But when I execute I am getting mvn: command not found error Java and Maven path is set correctly in global tool configuration (I am sure because I am able to execute other maven projects, only pipeline is failing.)
Console output:
Running on Jenkins in /Users/abacker/.jenkins/workspace/parallelTestNG
[Pipeline] {
[Pipeline] timestamps
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Just Testing)
[Pipeline] git
00:03:52 No credentials specified
00:03:52 > git rev-parse --is-inside-work-tree # timeout=10
00:03:52 Fetching changes from the remote Git repository
00:03:52 > git config remote.origin.url https://github.com/myRepo.git # timeout=10
00:03:52 Fetching upstream changes from https://github.com/myRepo.git
00:03:52 > git --version # timeout=10
00:03:52 > git fetch --tags --force --progress -- https://github.com/myRepo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
00:03:54 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
00:03:54 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
00:03:54 Checking out Revision e82f48106aa72d0275591926d9cd3226ba0fefd7 (refs/remotes/origin/master)
00:03:54 > git config core.sparsecheckout # timeout=10
00:03:54 > git checkout -f e82f48106aa72d0275591926d9cd3226ba0fefd7 # timeout=10
00:03:54 > git branch -a -v --no-abbrev # timeout=10
00:03:54 > git branch -D master # timeout=10
00:03:54 > git checkout -b master e82f48106aa72d0275591926d9cd3226ba0fefd7 # timeout=10
00:03:54 Commit message: "First commit"
00:03:54 > git rev-list --no-walk e82f48106aa72d0275591926d9cd3226ba0fefd7 # timeout=10
[Pipeline] script
[Pipeline] {
[Pipeline] sh
00:03:54 + mvn test
00:03:54 /Users/abacker/.jenkins/workspace/parallelTestNG@tmp/durable-818e64a8/script.sh: line 1: mvn: command not found
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
How can I fix this issue?
Solution
You don't have any tools declared for your maven project.
This would be a good starting point for running mvn goals from Jenkins. Declarative maven project.
Answered By - vijay
Answer Checked By - Marilyn (JavaFixing Volunteer)