Ivan Stoyanov
Ivan Stoyanov

Reputation: 5482

How to get artifactId and version from pom in a Jenkins Multibranch Pipeline plugin

I have set up Jenkins with the Multibranch Pipeline plugin, and I have configured it to trigger a build when there is a commit in a GitHub repository. I want to copy the .jar file, that is created by the maven build to a custom directory. To do that I have to specify the name of the file. The problem is that the name of the file contains the artifactId and the version from the pom.xml file. And the version changes quite often.

Is there a way to get the artifactId and version in Jenkins from the pom.xml file? I have red this blog post, but it says that these Jenkins variables work only if I create a Maven project in Jenkins.

Upvotes: 2

Views: 7631

Answers (1)

Krzysztof Krasoń
Krzysztof Krasoń

Reputation: 27496

You can do:

pom = readMavenPom file: 'pom.xml'
pom.artifactId
pom.version

You will need Pipeline Utility Steps plugin for this to work.

Upvotes: 3

Related Questions