不能在Jenkinsfile中使用readMavenPom

时间:2016-05-12 20:40:07

标签: jenkins jenkins-workflow jenkins-2

我正在使用Jenkins文件与Jenkins 2.0一起使用。无法识别readMavenPom方法。是否有一些我缺少的配置可以使它可用?

My Jenkinsfile:

node {
  stage 'Checkout'
  checkout scm
  env.PATH = "${tool 'maven-3'}/bin:${env.PATH}"
  stage 'Build'
  def pom = readMavenPom file: 'pom.xml'
  echo "${pom}"
  sh "mvn -DskipTests=true verify"
}

运行时,我收到以下错误:

java.lang.NoSuchMethodError: No such DSL method 'readMavenPom' found among
[AWSEBDeployment, archive, bat, build, catchError, checkout, deleteDir, dir, echo,
emailext, error, fileExists, git, input, isUnix, load, mail, node, parallel,
properties, pwd, readFile, retry, sh, slackSend, sleep, stage, stash, step, svn,
timeout, tool, unarchive, unstash, waitUntil, withCredentials, withEnv, wrap,
writeFile, ws]

2 个答案:

答案 0 :(得分:53)

我需要安装pipeline-utility-steps插件。

答案 1 :(得分:0)

在使用此步骤之前,请注意writeMavenPom / readMavenPom文档中的以下内容:

避免使用此步骤并读取MavenPom。最好使用sh步骤来运行mvn目标

https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#writemavenpom-write-a-maven-project-file