I am running Eclipse with Maven, eGit and TestNG plugins, with my tests running against SauceLabs.
I would like to get the project's current Git branch name in the Maven run configuration so my code can see it at runtime and name the SauceLabs session appropriately.
A typical current Maven goals line in a run configuration looks like this:
-DtestNG.suiteXmlFile="config/regress_saucelabs.xml" clean -X test
I would like to be able to write something like the following instead:
-DtestNG.suiteXmlFile="config/regress_saucelabs.xml" -Dgit.branch=$ECLIPSE_GIT_BRANCH clean -X test
where ECLIPSE_GIT_BRANCH is an Eclipse variable that gets substituted when the run configuration is used.
Runtime solutions are a last resort, because the test code needs to also run in environments where the source repository is not available.
Strongly prefer injecting the branch name at build time, on the Maven command line. Getting it as a POM variable would work well too.