-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Branch name always set to HEAD in Gitlab build #362
Comments
Could you try building locally and setting the CI envvars to arbitrary values locally until you can reproduce the issue locally? See https://docs.gitlab.com/ee/ci/variables/predefined_variables.html. Also, a binlog from that repro would be super helpful to determine what actually is being set and where during the build. Just dun |
I created a new clean project to only emphasize on the GitInfo issue. It gives the same result.
Actual
Output local build:
Output local checkout specific commit:
Set environment variables locally to simulate Gitlab environment and build with buildlog:
Ouput with these manually set environment variables:
Ouput Gitlab build:
Note: the latter two indeed produce the same result. |
GitInfo does not populate The GitInfo way is strictly through git commands: https://github.com/devlooped/GitInfo/blob/main/src/GitInfo/build/GitInfo.targets#L405-L435 My approach to defaulting RepositoryBranch is sprinkled in a few PRs here and there, see https://github.com/search?q=repositorybranch%20author%3Akzu&type=issues. Personally, I think this should be done by dotnet/sourcelink since that's the one providing source control info nowadays. |
The package that does this for you, is ThisAssembly.Git. Which, I'd say is the natural successor to this package. |
Bug description
When building locally, branch name is correctly filled in. But building on a Gitlab runner, the branch name is always HEAD. This has to do with Gitlab always checking out specific commit and not full branch, which makes sense.
My current workaround is to add following snippet to my .csproj, after including GitInfo, which basically overrides the generated GitBranch property when on CI:
In GitInfo
src/Directory.Build.targets
I see:So this snipped should (ultimately) set the 'RepositoryBranch' to Gitlab variable CI_COMMIT_BRANCH.
So is this a bug, or am I doing anything wrong?
Steps to Reproduce
Create or use an existing dotnet project and create a branch 'mybranch' in the git repo and use following project configuration.
Current .csproj (or Build.props) snippet:
gitlab-ci.yml:
Then push to Gitlab.
Expected Behavior
Gitlab runner should display Version detected and Product Version during build, which should be something like
0.0.1-mybranch+03d5aff
and not:
0.0.1-HEAD+03d5aff
Version Info
GitInfo Version="3.3.4"
The text was updated successfully, but these errors were encountered: