cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.92k stars 729 forks source link

GitVersion 5.7.0 NullReferenceException on Azure DevOps #3439

Closed ArtjomP closed 2 years ago

ArtjomP commented 3 years ago

Prerequisites

Cake runner

Cake .NET Tool

Cake version

1.2.0

Operating system

Windows

Operating system architecture

64-Bit

CI Server

Azure DevOps

What are you seeing?

Can't execute GitVersion on Azure DevOps pipeline. It works locally.

What is expected?

GitVersion should execute successfuly

Steps to Reproduce

Run pipeline

Output log

INFO [08/30/21 6:38:15:36] Applicable build agent found: 'AzurePipelines'. INFO [08/30/21 6:38:15:42] Working directory: D:\a\1\s INFO [08/30/21 6:38:15:47] Branch from build environment: refs/heads/my-branch INFO [08/30/21 6:38:15:47] Project root is: D:\a\1\s\ INFO [08/30/21 6:38:15:47] DotGit directory is: D:\a\1\s.git INFO [08/30/21 6:38:15:47] Begin: Normalizing git directory for branch 'refs/heads/my-branch' INFO [08/30/21 6:38:15:53] One remote found (origin -> 'https://test.visualstudio.com/TEST/_git/TestApp'). INFO [08/30/21 6:38:15:54] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories INFO [08/30/21 6:38:15:55] Creating local branch my-branch INFO [08/30/21 6:38:16:86] Creating local branch from remote tracking 'refs/remotes/origin/b80283647d922c9a28032c32a6e16d2041586fc4'. INFO [08/30/21 6:38:16:88] HEAD points at branch 'refs/heads/my-branch'. INFO [08/30/21 6:38:16:88] End: Normalizing git directory for branch 'refs/heads/my-branch' (Took: 1,404.57ms) INFO [08/30/21 6:38:16:89] Begin: Loading version variables from disk cache INFO [08/30/21 6:38:16:90] Cache file D:\a\1\s.git\gitversion_cache\9613914979AC68708F2A6795953BDF3E3C7BF557.yml not found. INFO [08/30/21 6:38:16:90] End: Loading version variables from disk cache (Took: 1.08ms) INFO [08/30/21 6:38:16:91] Using latest commit on specified branch INFO [08/30/21 6:38:16:92] No branch configuration found for branch my-branch, falling back to default configuration INFO [08/30/21 6:38:16:92] Begin: Attempting to inherit branch configuration from parent branch INFO [08/30/21 6:38:16:93] End: Attempting to inherit branch configuration from parent branch (Took: 6.47ms) ERROR [08/30/21 6:38:16:94] An unexpected error occurred: System.NullReferenceException: Object reference not set to an instance of an object. at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle) at LibGit2Sharp.Core.Proxy.git_commit_author(ObjectHandle obj) at LibGit2Sharp.Core.LazyGroup1.Dependent2.LibGit2Sharp.Core.LazyGroup.IEvaluator.Evaluate(TInput input) at LibGit2Sharp.Core.LazyGroup1.<Evaluate>b__6_0(T input) at LibGit2Sharp.Core.GitObjectLazyGroup.EvaluateInternal(Action1 evaluator) at LibGit2Sharp.Core.LazyGroup1.Evaluate() at LibGit2Sharp.Core.LazyGroup1.Dependent2.Evaluate() at LibGit2Sharp.Core.LazyGroup1.Dependent2.get_Value() at LibGit2Sharp.Commit.get_Committer() at GitVersion.Commit..ctor(Commit innerCommit) at GitVersion.Commit.<>c.<.ctor>b__3_0(Commit parent) at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.Count[TSource](IEnumerable1 source) at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList1 excludedInheritBranches) at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList1 excludedInheritBranches) at GitVersion.GitVersionContextFactory.Create(GitVersionOptions gitVersionOptions) at GitVersion.GitVersionCoreModule.<>c__DisplayClass0_0.<RegisterTypes>b__1() at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue() at System.Lazy`1.get_Value() at GitVersion.VersionCalculation.NextVersionCalculator.get_context() at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) INFO [08/30/21 6:38:16:94] Attempting to show the current git graph (please include in issue): INFO [08/30/21 6:38:16:94] Showing max of 100 commits INFO [08/30/21 6:38:17:04] * b802836 5 minutes ago (grafted, HEAD -> my-branch, origin/b80283647d922c9a28032c32a6e16d2041586fc4, b80283647d922c9a28032c32a6e16d2041586fc4)

Error: System.AggregateException: One or more errors occurred. ---> Cake.Core.CakeException: GitVersion: Process returned an error (exit code 1). at Cake.Core.Tooling.Tool1.ProcessExitCode(Int32 exitCode) at Cake.Core.Tooling.Tool1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction)

devlead commented 3 years ago

So upgraded Cake itself to use GitVersion 5.7.0 https://github.com/cake-build/cake/blob/50e9b6f5f249acff01a8a913a867b8df5a7d97c6/build.cake#L13

And builds seems to succeed fine on Azure Pipelines https://dev.azure.com/cake-build/Cake/_build/results?buildId=19806&view=logs&j=fd490c07-0b22-5182-fac9-6d67fe1e939b&t=eae017ea-0d55-5834-e313-398fb5d39f4c&l=18

How are you installing GitVersion, can you share more details or a repro?

Cake shells to the gitversion tool, so the issue might be upstream with GitVersion and not Cake. Or something with the environment, like i.e. a too shallow clone, causing issues for GitVersion. Does it work locally?

ArtjomP commented 3 years ago

Thank you for your reply. I install GitVersion this way (at the beginning of my.cake file): #tool nuget:?package=GitVersion.CommandLine&version=5.7.0 It looks like the problem is in the environment. I could not find out what was changed exactly because the previous commit that worked before started falling with the same error. Azure DevOps hosted image version is the same also. It works locally.

devlead commented 3 years ago

Do you get the same error if you instead use the Global tool and install using?

#tool dotnet:?package=GitVersion.Tool&version=5.7.0

ArtjomP commented 3 years ago

Thx. I changed in my.cake file: #tool nuget:?package=GitVersion.CommandLine&version=5.7.0 to #tool dotnet:?package=GitVersion.Tool&version=5.7.0 and get the same error

mrhorihan commented 2 years ago

I am having the same issue and I looked at the pipeline in https://dev.azure.com/cake-build/Cake/_build/results?buildId=19806&view=logs&j=fd490c07-0b22-5182-fac9-6d67fe1e939b&t=eae017ea-0d55-5834-e313-398fb5d39f4c&l=18 and it is set to use Environment: windows-2016. But it fails if you try to use windows-2019

devlead commented 2 years ago

This is an issue with GitVersion unrelated to Cake, but I believe it's fixed if you switch to a newer version which uses a newer version of LibGit2Sharp

#tool dotnet:?package=GitVersion.Tool&version=5.8.1

https://www.nuget.org/packages/GitVersion.Tool

mrhorihan commented 2 years ago

updated to GetVersion.Tool version 5.8.1 and still getting the following error with this cake statement version = GitVersion();

`An error occurred when executing task 'SetVersion'. Error in SetVersion in version.cake Cake.Core.CakeException: GitVersion: Process returned an error (exit code 1).

======================================== SetPackageVersions

Executing task: SetPackageVersions at Cake.Core.Tooling.Tool1.ProcessExitCode(Int32 exitCode) at Cake.Core.Tooling.Tool1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action1 postAction) at Cake.Common.Tools.GitVersion.GitVersionRunner.Run(GitVersionSettings settings) at Submission#0.GitVersion() at Submission#0.<<Initialize>>b__0_28() at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass24_0.<Does>b__0(ICakeContext x) at Cake.Core.CakeTask.<Execute>d__43.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Cake.Core.DefaultExecutionStrategy.<ExecuteAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext() An error occurred when executing task 'SetPackageVersions'.

devlead commented 2 years ago

Do you have the same issue with Cake version 2.1 and the latest version of GitVersion (5.9.0)?

#tool dotnet:?package=GitVersion.Tool&version=5.9.0
ArtjomP commented 2 years ago

It works, thank you!

devlead commented 2 years ago

Excellent 👍