Maven - How pass the Build Name from Command line ?

Problem

When reporting a build to Sealights via Maven from the command line, you need to provide a different build name each time you create a new Build Session ID.

Sample of JSON configuration file
{ ... "buildName": "${BUILD_NUMBER}", ... }

Instead of updating manually your pom.xml or the JSON configuration file, you have several ways to dynamically update the Build Name parameter passed to Sealights.

Solutions

Maven Parameter from Command line to Sealights plugin

When using a variable in the Maven configuration (JSON or pom.xml), you can override its value via -D flag in the command line 

mvn clean install -Psealights -DBUILD_NUMBER=3

Using a timestamp variable from the command line

In order to use a timestamp to report the build to Sealights, please prefer to use for example

mvn clean install -Psealights -DBUILD_NUMBER=`date +"%y%m%d_%H%M"`

 

Timestamp defined as part of the Maven configuration  

Using an timestamp generated by Sealights

Sealights Java agents supports a specific SL_Timestamp variable the JSON configuration file to set the Sealights Maven plugin generating automatically a time stamp as a default buildname.
The default format is yyyy.MM.dd-hh.mm.

Sample of JSON configuration file

Using a timestamp variable in pom.xml

Maven provides a built-in property called ${maven.build.timestamp} that provides the time the build was initiated and this can be used in your Sealights profile after wrapping in another property

Pom.xml with timestamp

From now on, you can use this property ${timestamp} either in the Sealights profile directly in the pom.xml or inside the JSON configuration file.

Sample of JSON configuration file
Sample of profile using timestamp property