Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access maven property from Jenkins?

I have a maven project in which I have a property. I want to access it from Jenkins.

POM snippet:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <timestamp>${build.time}</timestamp>
    <outputFolder>C:/AutomationTestReports/${project.name}/ExecutionReport${timestamp}</outputFolder>
</properties>

This output folder property gets evaluated at runtime. I want to access this property in Jenkins to navigate to the output folder which gets generated as per the time stamp. For this to happen I need to capture this output folder property in Jenkins, which I am not able to do.

Using this output folder only I will be able to navigate to the folder to access the result file.

Question: How to access Maven properties from Jenkins job?

like image 961
Rajit s rajan Avatar asked Feb 07 '23 04:02

Rajit s rajan


1 Answers

In the current version of Jenkins there is a nice and simple way to achieve this using "readMavenPom()".

For example, I want to read the version of the pom.xml file. But if it is using the newer maven "revision" practice, I need to read that "revision" value from the properties defined in the pom.xml.

      def pomVersion = readMavenPom().version   // read version
      if (pomVersion.equals("\${revision}"))    // using revision strategy, read revision property
      {
        pomVersion = readMavenPom().properties['revision']
      }

So the best way is to use

readMavenPom().properties['PROPETY_NAME']
like image 92
bbezanson Avatar answered Feb 12 '23 09:02

bbezanson