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.
The build number is obtained from scm. You can then place that build number in metadata, which can be accessed from your app, if desired. The mojo also has a couple of extra functions to ensure you get the proper build number. First, your local repository is checked to make sure it is up to date.
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}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With