e-gineering/gitflow-helper-maven-plugin

Detect current branch name without external dependencies

raehalme opened this issue · 9 comments

I would appreciate if this great plugin could resolve the current Git branch name without external dependencies. I'm not too happy about modifying our CI agents to set environment variables as I would like to configuration to be kept as simple and clean as possible.

One solution is to use the plugin org.codehaus.mojo:buildnumber-maven-plugin which is capable of setting the current branch name into a property (by default scmBranch). This property can be referenced in the gitBranchExpression property as long as the plugin is allowed to be executed.

Would you be willing to consider adding the plugin org.codehaus.mojo:buildnumber-maven-plugin to the set of retained plugins?

Would it make sense to make the list of retained plugins to be configurable? It would allow other similar plugins to be easily configured as well.

Actually after testing this by retaining also the buildnumber-maven-plugin plugin the process no longer runs as intended. For example, test and compile are now again included in the build process when running on the master branch.

It would probably be best if the branch name could be resolved without the help of any other plugins (to avoid them messing up the build process). I'll have a look if we could easily incorporate the logic in buildnumber-maven-plugin to resolve the current branch directly in this plugin.

I now have a version available which uses ScmManager and the Git provider to resolve the current branch name. Would it be okay to replace the default value ${env.GIT_BRANCH} with this implementation? You could still specify ${env.GIT_BRANCH} explicitly in the configuration, if preferred.

Interesting. I'd be curious to see a pull request!

The reason I used '${env.GIT_BRANCH}' was that it was (hah provided) by my CI server (Jenkins), and easy to detect if it wasn't set at all (in a local developer environment)

Sure thing! Should I target the development branch? Looks like it's a bit out of date, could you maybe update it?

Thanks! You can see my changes in #53.

So what's funny, is that you probably could have just put..

<gitBranchExpression>${project.scm.developerConnection}</gitBranchExpression> and just ignored all the code changes. :-D ohhhh I wish I'd thought of that sooner.

Oh, wait... no that wouldn't get the branch. :-)

Yeah, it wouldn't have worked for the branch name. :-)