0

After we fetch POM model like described in Krzysztof Krasoń's answer in extract pom version in a jenkins pipeline. Call to pom.version returns the fully qualified name of the artifact and not just the version.

For example

@NonCPS
def version() {
    pom = readMavenPom file: 'pom.xml'
    pom.version
}

for

<groupId>com.test.app</groupId>
<artifactId>app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

will produce

com.test.app:app:pom:1.0.0-SNAPSHOT

Is there a way to return just the version part from returned Model without doing any String manipulation?

Matej
  • 7,728
  • 4
  • 23
  • 30
  • 2
    `pom.version` should return `1.0-SNAPSHOT`. Are you sure you are using it right? Put the full context so we can help you. – Vitalii Vitrenko Aug 04 '17 at 17:16
  • @VitaliiVitrenko I would expect to get `1.0.0-SNAPSHOT` and not `1.0-SNAPSHOT`... – khmarbaise Aug 05 '17 at 21:42
  • @khmarbaise just a typo. It will return what you specified in `` tag. – Vitalii Vitrenko Aug 05 '17 at 22:18
  • @VitaliiVitrenko Thanks for clearing up. That was my assumption.. – khmarbaise Aug 06 '17 at 14:42
  • @Vitalii Vitrenko What else would you need? I can't disclosure everything due to company policies. edit: I've put complete version of function we tried to use to extract version from the pom file. – Matej Aug 08 '17 at 08:04
  • @VitaliiVitrenko Ok, so I've figured it out (partially). If I remove NonCPS annotation it would work as expected, with the annotation present what is being returned is an instance of the Model class (I'm not sure why in this case, so if anyone could explain?). I had that class present due to testing different approaches, of which one had non-serializable instance so I had to put the annotation in use. Now if I remove it, function will return a String containing the proper version from pom file. – Matej Aug 08 '17 at 08:17

1 Answers1

1

You should not call regular (CPS-transformed) methods, or Pipeline steps inside @NonCPS methods because they requires CPS-transformation.
See more in README.md.

Vitalii Vitrenko
  • 9,763
  • 4
  • 43
  • 62