Pom.xml environment variable with default deviation

I would like to be able to use an environment variable if it is set or the default value that I set in pom.xml, like $ {VARIABLE: -default} in bash. Is it possible? Sort of:

${env.BUILD_NUMBER:0} 
+5
source share
2 answers

To achieve this, you can use profiles:

 <profiles> <profile> <id>buildnumber-defined</id> <activation> <property> <name>env.BUILD_NUMBER</name> </property> </activation> <properties> <buildnumber>${env.BUILD_NUMBER}</buildnumber> </properties> </profile> <profile> <id>buildnumber-undefined</id> <activation> <property> <name>!env.BUILD_NUMBER</name> </property> </activation> <properties> <buildnumber>0</buildnumber> </properties> </profile> </profiles> 

A bit more verbose than bash ...

+6
source

I was not very happy with the approach taken, so I simplified it a bit.

Basically, the default property is set in the normal properties block and is redefined if necessary (instead of the effective switch statement):

 <properties> <!-- Sane default --> <buildNumber>0</buildNumber> <!-- the other props you use --> </properties> <profiles> <profile> <id>ci</id> <activation> <property> <name>env.buildNumber</name> </property> </activation> <properties> <!-- Override only if necessary --> <buildNumber>${env.buildNumber}</buildNumber> </properties> </profile> </profiles> 
+10
source

Source: https://habr.com/ru/post/1240444/


All Articles