11
votes

I am currently trying to implement pipeline in jenkins using jenkinsfile and i am executing a maven project on windows machine. I am creating a pipeline job in jenkins and i have checked in this file in my github repository and when i am running the job in jenkins , i am getting following error.

My jenkinsfile:

    pipeline {
        agent any
        stages {
            stage('Compile stage') {
                steps {
                    maven(maven : 'Maven_3.5.2'){
                        bat "mvn clean compile"
                }
            }
        }

             stage('testing stage') {
                 steps {
                    maven(maven : 'Maven_3.5.2'){
                        bat "mvn test"
                }
            }
        }

              stage('deployment stage') {
                  steps {
                    maven(maven : 'Maven_3.5.2'){
                        bat "mvn deploy"
                }
            }
        }

      }

    }

I am getting below error when i am running it through jenkins job- Jenkins error:

java.lang.NoSuchMethodError: No such DSL method 'withMaven' found among steps [archive, bat, build, catchError, checkout, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, getContext, git, input, isUnix, library, libraryResource, load, mail, milestone, node, parallel, powershell, properties, pwd, readFile, readTrusted, resolveScm, retry, script, sh, sleep, stage, stash, step, svn, timeout, timestamps, tm, tool, unarchive, unstash, validateDeclarativePipeline, waitUntil, withContext, withCredentials, withDockerContainer, withDockerRegistry, withDockerServer, withEnv, wrap, writeFile, ws] or symbols [all, allOf, always, ant, antFromApache, antOutcome, antTarget, any, anyOf, apiToken, architecture, archiveArtifacts, artifactManager, authorizationMatrix, batchFile, booleanParam, branch,

Any help?

4

4 Answers

17
votes

This means you don't have withMaven as an available DSL method. Most of the time this means you don't have a plugin installed. In this case, the Pipeline Maven Integration plugin is required. https://plugins.jenkins.io/pipeline-maven/

6
votes

Try this:

pipeline {

    agent any
    tools {
        maven 'Maven_3.5.2' 
    }
    stages {
        stage('Compile stage') {
            steps {
                bat "mvn clean compile" 
        }
    }

         stage('testing stage') {
             steps {
                bat "mvn test"
        }
    }

          stage('deployment stage') {
              steps {
                bat "mvn deploy"
        }
    }

  }

}

Reference: https://jenkins.io/doc/book/pipeline/syntax/

3
votes

On top of Rob Hales' answer, it is called "Pipeline Maven Integration Plugin" in Jenkins ver. 2.73.3 or later

0
votes

You need to install all listed "pipeline" plugin and error no longer will be there.