GitTools / GitVersion

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

[ISSUE]: Null-reference exception when running GitVersion task in DevOps pipeline #4082

Closed arp-mbender closed 4 months ago

arp-mbender commented 4 months ago

Prerequisites

GitVersion package

AzureDevops task

GitVersion version

5.12.0

Operating system

Windows

What are you seeing?

My DevOps pipeline fails after the the execute task:

steps:
- task: gittools.gittools.setup-gitversion-task.gitversion/setup@0
  displayName: Install GitVersion
  inputs:
    versionSpec: '5.x'
- task: gittools.gittools.execute-gitversion-task.gitversion/execute@0
  displayName: Use GitVersion

The output of this task:

Starting: Use GitVersion
==============================================================================
Task         : Execute GitVersion Task
Description  : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version      : 0.13.6
Author       : GitTools Contributors
Help         : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Agent: 'Azure Pipelines'
Command: git rev-parse --is-shallow-repository
C:\agents\3.241.0\externals\git\cmd\git.exe rev-parse --is-shallow-repository
fatal: not a git repository (or any of the parent directories): .git
Command: dotnet-gitversion D:/a/1/s /output json /output buildserver
C:\hostedtoolcache\windows\GitVersion.Tool\5.12.0\x64\dotnet-gitversion.exe D:/a/1/s /output json /output buildserver
INFO [07/04/24 13:28:46:94] Working directory: D:/a/1/s
INFO [07/04/24 13:28:46:99] Project root is: D:\a\1\s\
INFO [07/04/24 13:28:46:99] DotGit directory is: D:\a\1\s\.git
INFO [07/04/24 13:28:46:99] Branch from build environment: refs/heads/dll-deployment-pipeline
INFO [07/04/24 13:28:47:00] Begin: Normalizing git directory for branch 'refs/heads/dll-deployment-pipeline'
  INFO [07/04/24 13:28:47:05] One remote found (origin -> 'https://REDACTED').
  INFO [07/04/24 13:28:47:06] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [07/04/24 13:28:47:06] Creating local branch dll-deployment-pipeline
  INFO [07/04/24 13:28:47:22] Creating local branch from remote tracking 'refs/remotes/origin/9ddb48f0f54d688ac8ac31232de4a64d5960300e'.
  INFO [07/04/24 13:28:47:23] HEAD points at branch 'refs/heads/dll-deployment-pipeline'.
  INFO [07/04/24 13:28:47:23] End: Normalizing git directory for branch 'refs/heads/dll-deployment-pipeline' (Took: 237.17ms)
  INFO [07/04/24 13:28:47:25] Begin: Loading version variables from disk cache
    INFO [07/04/24 13:28:47:25] Cache file D:\a\1\s\.git\gitversion_cache\7FDECC0EF7F3A7D9DE80FF11E5F9298A24633066.yml not found.
  ERROR [07/04/24 13:28:47:59] 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) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
   at LibGit2Sharp.Core.Proxy.git_commit_author(ObjectHandle obj) in /_/LibGit2Sharp/Core/Proxy.cs:line 289
   at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.LibGit2Sharp.Core.LazyGroup<T>.IEvaluator<TInput>.Evaluate(TInput input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 88
   at LibGit2Sharp.Core.LazyGroup`1.<Evaluate>b__6_0(T input) in /_/LibGit2Sharp/Core/LazyGroup.cs:line 36
   at LibGit2Sharp.Core.GitObjectLazyGroup.EvaluateInternal(Action`1 evaluator) in /_/LibGit2Sharp/Core/GitObjectLazyGroup.cs:line 20
   at LibGit2Sharp.Core.LazyGroup`1.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 34
   at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.Evaluate() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 80
   at LibGit2Sharp.Core.LazyGroup`1.Dependent`2.get_Value() in /_/LibGit2Sharp/Core/LazyGroup.cs:line 73
   at LibGit2Sharp.Commit.get_Committer() in /_/LibGit2Sharp/Commit.cs:line 87
   at GitVersion.Commit..ctor(Commit innerCommit) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 17
   at GitVersion.Commit.<>c.<.ctor>b__3_0(Commit parent) in D:\a\GitVersion\GitVersion\src\GitVersion.LibGit2Sharp\Git\Commit.cs:line 16
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)

What is expected?

I'd expect the task to succeed.

Steps to Reproduce

I... honestly cannot say what's going on here. I can run GitVersion locally without issues (same version), so this can be some kind of weird edge case.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

No response

arp-mbender commented 4 months ago

Found the cause. The default checkout was, apparently, shallow, which caused GitVer to fail. I wasn't aware that would be the default for us. I've added

- checkout: self
   fetchDepth: 0

and now it works.