GitTools / GitVersion

From git log to SemVer in no time
https://gitversion.net/docs/
MIT License
2.87k stars 654 forks source link

GitVersion in docker image fails on TeamCity but suceeds locally #2142

Closed anekdoti closed 4 years ago

anekdoti commented 4 years ago

I have a Dockerfile that creates an image from gittools/gitversion:5.1.4-linux. It copies the content of the context folder into a workdir /src in the image. The copy includes in particular the .git folder and a GitVersion.yml. Afterwards, Gitversion is invoked using dotnet /app/GitVersion.dll /showvariable SemVer .

Running docker build . locally in the root folder of a cloned git repository works fine and computes the SemVer based on the git history.

However, when running the docker build as a build step in TeamCity using a docker runner, the following exception, similar to the one described in #1753, is thrown:

System.ArgumentNullException: Value cannot be null. Parameter name: filter.IncludeReachableFrom at LibGit2Sharp.CommitLog.QueryBy(CommitFilter filter) 
    at GitVersion.VersionCalculation.FallbackVersionStrategy.GetVersions(GitVersionContext context)+MoveNext() in D: \GitVersion\GitVersion\src\GitVersionCore\VersionCalculation\BaseVersionCalculators\FallbackVersionStrategy.cs:line 22 at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext() 
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToList() 
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) 
    at GitVersion.VersionCalculation.BaseVersionCalculator.GetBaseVersion(GitVersionContext context) 
    at GitVersion.VersionCalculation.NextVersionCalculator.FindVersionInternal(GitVersionContext context) in D: \GitVersion\GitVersion\src\GitVersionCore\VersionCalculation\NextVersionCalculator.cs:line 79 
    at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context) in D: \GitVersion\GitVersion\src\GitVersionCore\VersionCalculation\NextVersionCalculator.cs:line 45 
    at GitVersion.GitVersionCalculator.<>c__DisplayClass13_0.<ExecuteInternal>b__0(IRepository repo) in D: \GitVersion\GitVersion\src\GitVersionCore\GitVersionCalculator.cs:line 110 
    at GitVersion.Extensions.LibGitExtensions.WithRepository[TResult](String dotGitDirectory, Func`2 action) in D: \GitVersion\GitVersion\src\GitVersionCore\Extensions\LibGitExtensions.cs:line 16 
    at GitVersion.GitVersionCalculator.GetCachedGitVersion (String targetBranch, String commitId, Config overrideConfig, Boolean noCache) in D: \GitVersion\GitVersion\src\GitVersionCore\GitVersionCalculator.cs:line 83 
    at GitVersion.ExecCommand.Execute() in D: \GitVersion\GitVersion\src\GitVersionExe\ExecCommand.cs:line 39 
    at GitVersion.GitVersionExecutor.VerifyArgumentsAndRun(Arguments arguments) in D: \GitVersion\GitVersion\src\GitVersionExe\GitVersionExecutor.cs:line 117 

The environment variable Git_Branch is setup properly in the Dockerfile, and the .git folder is copied correctly (I listed its content in the Dockerfile to be sure).

I would be very interested to find out the reason and possible solutions for this problem.

asbjornu commented 4 years ago

Please have a look at how I've managed to get GitVersion to work to see whether it gives you any ideas for how to fix your problems:

https://github.com/SwedbankPay/swedbank-pay-magento2-checkout/blob/2ee48c421403ddd4a64215fb783f30b17c2b1724/.travis.yml#L17-L34

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

john-shaskin commented 2 years ago

Thank you for sharing that @asbjornu. We're running our builds on TeamCity, and the fact that GitVersion now seems to require the master branch to be present was causing me issues in upgrading to the latest GitVersion as well. Definitely kind of lame that you need to force the build to check out master or main, but I'm happy this workaround solves my problem.