It's captured as HEAD
. I suspect it may be a side-effect of how the Concourse git resource checks out the code.
Comment From: dreis2211
@wilkinsona Hopefully of interest https://github.com/concourse/git-resource/issues/198
Comment From: dreis2211
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
}
Comment From: scottfrederick
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.
Comment From: mbhave
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
.
Comment From: maksym-nazarenko
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.
Comment From: wilkinsona
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
.
Comment From: philwebb
Closing in favor of PR #19658