git-commit-id-maven-plugin
git-commit-id-maven-plugin copied to clipboard
Azure DevOps - Git branch name incomplete if it contains a slash
Azure Devops - Incomplete git branch name
Relating to feature #438
The predefined variables in Azure Devops can lead to incomplete branch names: According to https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#build-variables you can see that BUILD_SOURCEBRANCHNAME only contains everything behind the last slash ('/'). This is incomplete however if the branchname itself contains a slash. There is an issue on DevOps side, but it seems they are not changing that behavior https://developercommunity.visualstudio.com/t/azure-devops-build-variable-buildsourcebranchname/519811
Maybe in this plugin at least we can? If so, the solution should probably be using BUILD_SOURCEBRANCH (complete name, including "refs/heads/") and statically removed the "refs/heads/" at the beginning
Steps to Reproduce
Have a branch with a slash in its name (e.g. "feature/iss123_description")
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
<failOnNoGitDirectory>true</failOnNoGitDirectory>
<dotGitDirectory>${project.basedir}../../../.git</dotGitDirectory>
<verbose>true</verbose>
</configuration>
</plugin>
Build the project in a AzureDevops Pipeline
Result: The git.properties file contains the branch as "git.branch=ss123_description"
Expected behavior
- The git.properties file should contain the branch as "git.branch=feature/iss123_description"
Additional context
For reproducibility please provide the following:
- plugin version 5.0.0
- java version: AdaptOpenJDK 11
- maven version 3.6
- OS version Ubuntu 20.04
Hello thank you for raising this and linking the discussion on MS!
I find it very wrong that Build.SourceBranchName
effectively returns tools
for refs/heads/feature/tools
. Clearly you can disagree all day long that tools
is not the full name of the branch and that the behaviour is documented...I still find it wrong.
Anyhow indeed the plugin is currently using BUILD_SOURCEBRANCHNAME. I guess as you suggested the only option to solve this would be using BUILD_SOURCEBRANCH
and then manually stripping the refs/heads/
.