简体   繁体   中英

Jenkinsfile error- java.lang.NoSuchMethodError: No such DSL method 'withMaven' found among steps

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?

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/

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/

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

您需要安装所有列出的“管道”插件,错误将不再存在。

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM