Setting up a Pipeline build in Jenkins (Jenkins 2.7.2), copying the sample script for a git-based build gives: "no tool named M3 found". The relevant line in the Pipeline script is:
def mvnHome = tool 'M3'
You need to have Maven installation available to do builds. You can configure using Global Tool Configuration
and give name as 'M3'
def mvnHome = tool 'M3'
It says M3 is installed and assigns the return value to the mvnHome
make sure that the maven installation is configured in hudson.tasks.Maven.xml
as below with name you want (I have MAVEN3
below),
cat /var/lib/jenkins/hudson.tasks.Maven.xml
<?xml version='1.0' encoding='UTF-8'?>
<hudson.tasks.Maven_-DescriptorImpl>
<installations>
<hudson.tasks.Maven_-MavenInstallation>
<name>MAVEN3</name>
<home>/usr/share/apache-maven/</home>
<properties/>
</hudson.tasks.Maven_-MavenInstallation>
</installations>
</hudson.tasks.Maven_-DescriptorImpl>
Followed by jenkins restart
systemctl restart jenkins.service
It can be verified in UI as well,
Then, same variable can be used in pipeline script.
node {
def mvnHome
stage('Preparation') {
git url: 'https://github.com/prayagupd/eccount-rest.git', branch: 'REST-API-load-balancing'
mvnHome = tool 'MAVEN3'
}
stage('Build') {
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
}
stage('Results') {
junit '**/target/surefire-reports/TEST-*.xml'
archive 'target/*.jar'
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With