Azure DevOps - Git branch name incomplete if it contains a slash
Azure Devops - Incomplete git branch name
Relating to feature git-commit-id/git-commit-id-maven-plugin#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