Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure DevOps - Git branch name incomplete if it contains a slash #17

Closed
b509 opened this issue Jan 28, 2022 · 1 comment
Closed

Azure DevOps - Git branch name incomplete if it contains a slash #17

b509 opened this issue Jan 28, 2022 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@b509
Copy link

b509 commented Jan 28, 2022

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
@TheSnoozer
Copy link
Contributor

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/.

@TheSnoozer TheSnoozer added the bug Something isn't working label Feb 6, 2022
@TheSnoozer TheSnoozer transferred this issue from git-commit-id/git-commit-id-maven-plugin Apr 12, 2023
@TheSnoozer TheSnoozer added this to the 6.0.0 milestone May 4, 2023
@TheSnoozer TheSnoozer modified the milestones: 6.0.0, 6.0.0-rc.4 Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants