Skip to content
New issue

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

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

Already on GitHub? # to your account

git branch captured in the build scan is wrong #19614

Closed
wilkinsona opened this issue Jan 10, 2020 · 7 comments
Closed

git branch captured in the build scan is wrong #19614

wilkinsona opened this issue Jan 10, 2020 · 7 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@wilkinsona
Copy link
Member

It's captured as HEAD. I suspect it may be a side-effect of how the Concourse git resource checks out the code.

@wilkinsona wilkinsona added the type: task A general task label Jan 10, 2020
@wilkinsona wilkinsona added this to the 2.3.x milestone Jan 10, 2020
@dreis2211
Copy link
Contributor

@wilkinsona Hopefully of interest concourse/git-resource#198

@dreis2211
Copy link
Contributor

What about mapping HEAD to master? E.g. something like this:

--- a/gradle/build-scan-user-data.gradle
+++ b/gradle/build-scan-user-data.gradle
@@ -36,6 +36,9 @@ void addGitMetadata() {
                        link 'Git commit build scans', customValueSearchUrl([(commitIdLabel): gitCommitId])
                }
                if (gitBranchName) {
+                       // Concourse checks out master in detached HEAD state.
+                       // See (https://github.com/concourse/git-resource/issues/198)
+                       gitBranchName = 'HEAD'.equals(gitBranchName) ? 'master' : gitBranchName
                        tag gitBranchName
                        value 'Git branch', gitBranchName
                }

@scottfrederick
Copy link
Contributor

What about mapping HEAD to master

I'm not sure it's only master that gets cloned in a detached HEAD state, I believe any branch will get checked out that way.

@mbhave
Copy link
Contributor

mbhave commented Jan 10, 2020

It's only master that publishes the build scan as of now I think. But yeah, that probably won't work once we fork 2.3.x.

@maksym-nazarenko
Copy link

what if we fetch the branch name from origin/HEAD like this:

if (gitBranchName) {
        if (gitBranchName == "HEAD") {
                def originBranchName = execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'origin/HEAD')
                if (originBranchName.startsWith("origin/")) {
                        originBranchName = originBranchName.substring("origin/".size())
                }

                if (originBranchName) {
                        gitBranchName = originBranchName
                }
        }

        tag gitBranchName
        value 'Git branch', gitBranchName
}

?

Sorry for poor code quality, I just want to express the idea.

@wilkinsona
Copy link
Member Author

Interesting idea, @Maxim-Nazarenko. Thanks. That'll work while Gradle is only used on master but I don't think it'll work once we've branched 2.3.x.

This is only a problem on CI and we already have the name of the branch there as a parameter. We could pass it into the job as an environment variable and then use it to set gitBranchName. If it's not set (as would be the case in a local build), we can fall back to git rev-parse … or git branch --show-current.

dreis2211 added a commit to dreis2211/spring-boot that referenced this issue Jan 12, 2020
@philwebb
Copy link
Member

Closing in favor of PR #19658

@philwebb philwebb removed the type: task A general task label Jan 13, 2020
@philwebb philwebb removed this from the 2.3.x milestone Jan 13, 2020
@philwebb philwebb added the status: superseded An issue that has been superseded by another label Jan 13, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants