Reputation: 27
I am really new with Jenkins and maven projects and starting to drive me crazy even with a simple sample project using https://github.com/jglick/simple-maven-project-with-tests.git
Also using the Pipeline sample script GitHub + Maven from Jenkins
stages {
stage('Build') {
steps {
// Get some code from a GitHub repository
git 'https://github.com/jglick/simple-maven-project-with-tests.git'
// Run Maven on a Unix agent.
sh "mvn -Dmaven.test.failure.ignore=true clean package"
But i'm getting the next error:
+ mvn -version
/var/lib/jenkins/workspace/app-maven@tmp/durable-dba02bb4/script.sh: line 1: mvn: command not found
I found an article which says to use this method for save the mvn path on a variable and use it:
steps {
// Get some code from a GitHub repository
git 'https://github.com/alvarosjf/maven-app.git'
// Run Maven on a Unix agent.
def mvnHome = tool name: '3.6.3', type: 'maven'
sh "${mvnHome}/bin/mvn -version"
//sh 'mvn -version'
But this is even worst showing an error at the startup
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: Not a valid stage section definition: "def mvnHome = tool name: '3.6.3', type: 'maven'". Some extra configuration is required. @ line 5, column 7.
stage('Build') {
^
1 error
Any trick to try and use a simple jenkins pipeline with Github webhooks + maven?
Upvotes: 1
Views: 4447
Reputation: 346
your pipeline code seems to be correct, but you need the used tool (in your script, maven in version 3.6.3) to be configured within Jenkins itself.
This can be done via:
"Manage Jenkins -> Configure Tools", within the maven section, add a new instance (choose any name you want, use this name also in your pipeline script tool name: 'your-name' type: 'maven'
) leave the rest as it is, which will install maven automatically via downloading from apache servers
Upvotes: 3