Cannot use readMavenPom in Jenkinsfile
Asked Answered
L

3

30

I am working on a Jenkinsfile for use with Jenkins 2.0. The readMavenPom method is not recognized. Is there some configuration I am missing to make this available?

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"
}

When run, I get the following error:

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]
Lightning answered 12/5, 2016 at 20:40 Comment(0)
L
87

I needed to install the pipeline-utility-steps plugin.

Lightning answered 12/5, 2016 at 22:15 Comment(0)
A
0

Before you use this step, note the below from writeMavenPom/readMavenPom documentation:

Avoid using this step and readMavenPom. It is better to use the sh step to run mvn goals

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

Alger answered 23/11, 2020 at 22:46 Comment(1)
(I found) Maybe because of github.com/jenkinsci/pipeline-utility-steps-plugin/pull/47Limnetic
W
0
  1. Use below command to read whole pom.xml in declarative pipeline :

     sh  ‘mvn -f  ./path-to-my-service/pom.xml help:evaluate -Dexpression=project -q -DforceStdout’
    
  2. For specific property in a pom.xml use same command with tag hierarchy :
    project.property.sub-property........and so on

       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;
    
Wendelina answered 6/6, 2023 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.