简体   繁体   中英

How to get current Git branch name in Eclipse run configurations

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.

I have never use it but it looks like JGit is what you are looking for ( https://doc.nuxeo.com/blog/jgit-example/ )

Another solution is to call the shell command git branch in Java and then parse the result.

Another solution using maven plugin is explained here : Put current git branch to project version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM