无法在Jenkinsfile中使用readMavenPom

aamkag61  于 2023-06-21  发布在  Jenkins
关注(0)|答案(3)|浏览(212)

我正在编写一个Jenkins文件,用于Jenkins 2.0。无法识别readMavenPom方法。我是否缺少某些配置以使其可用?
我的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]
mrwjdhj3

mrwjdhj31#

安装pipeline-utility-steps插件

gwo2fgha

gwo2fgha2#

在使用此步骤之前,请注意writeMavenPom/readMavenPom文档中的以下内容:
避免使用此步骤并readMavenPom。最好使用sh步骤来运行mvn目标
https://www.jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#writemavenpom-write-a-maven-project-file

kpbpu008

kpbpu0083#

1.使用以下命令读取声明性管道中的整个pom.xml:

sh  ‘mvn -f  ./path-to-my-service/pom.xml help:evaluate -Dexpression=project -q -DforceStdout’

1.对于pom.xml中的特定属性,请使用具有标记层次结构的相同命令:
项目.属性.子属性........等等

def pom_version = sh script: 'mvn -f ./path-to-my-service/pom.xml -DskipTests help:evaluate -Dexpression=project.version -q -DforceStdout', returnStdout: true;

   def pom_artifactId = sh script: 'mvn -f ./path-to-my-service/pom.xml -DskipTests help: evaluate -Dexpression=project.artifactId -q -DforceStdout', returnStdout: true;

   def pom_groupId = sh script: 'mvn -f ./path-to-my-service/pom.xml -DskipTests help:evaluate -Dexpression=project.groupId -q -DforceStdout', returnStdout: true;

相关问题