8

I am trying to read the Jenkins number using a maven pom.xml using the following code. The issue is that, the build is failing with the error as I have specified below. I referred to the official document given by Jenkins Building a software project. If I try to use any text instead of ${BUILD_NUMBER} it is getting printed in the console but not the variable.

POM Profile reference:

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <build.number>${BUILD_NUMBER}</build.number>
        </properties>
    </profile>
</profiles>

POM System Property:

<systemPropertyVariables>
    <buildnumber>${build.number}</buildnumber>
</systemPropertyVariables>

Please let me know if I am doing something wrong.

RevanProdigalKnight
  • 1,316
  • 1
  • 14
  • 23
Yellesh Chaparthi
  • 413
  • 1
  • 7
  • 8

1 Answers1

9

One thing I did to myself was to call a few maven commands before, like mvn versions:set and mvn -N versions:update-child-modules. My pom files are versioned x.y.z, so I make them look like x.y.z.$buildnumber. You can replace it enterelly by $buildnumber if you want, but dont forget maven will update the and commit it back to SCM, incrementing the minor version by 1. You have to handle this on the next build.

Please note that ${BUILD_NUMBER} is an envvar available on bash (and I can get it on my bash scripts), not a maven variable.

And as explained here: How to refer environment variable in POM.xml?, you can do ${env.variable_name}.

Community
  • 1
  • 1
Lovato
  • 2,250
  • 1
  • 16
  • 22
  • Thanks guys I now am able to get the Jenkins build number by using Maven. I use this in maven as a system parameters and it is getting the build number. – Yellesh Chaparthi Sep 08 '14 at 12:50
  • If this answer solved the problem, please accept this as correct, so others with similar problems can find a solution too. Best. – Lovato Sep 08 '14 at 12:54