Azure DevOps Yaml Pipline gitversion/execute failing ObjectHandle.op_Implicit(ObjectHandle handle) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
Asked Answered
R

2

6

Getting error when run task gitversion/execute on azure devops yaml pipeline 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 comming from ##[debug]fetchDepth=1 with not option to setup in yaml, as this was change as default value for Microsoft.

Repletion answered 22/9, 2022 at 14:15 Comment(0)
R
10

Option to setup fetch is hidden in ADO under pipeline Edit button -> Triggers -> enter image description here

Or use

variables:
  Agent.Source.Git.ShallowFetchDepth: 0

or if the repository is also checkout as dedicated task

steps:
  - checkout: self
    fetchDepth: 0
    clean: true
Repletion answered 22/9, 2022 at 14:15 Comment(1)
Awesome! Had a build with this error, and sure, it was exactly what you said here! But, the ShallowFetchDepth has to be greater than 1 in order to be able to find a version starting point, or turned completely off.Outcurve
S
6

This happens with pipelines created after Sept. 2022. If you're using a YAML pipeline, replace:

- checkout: self
  persistCredentials: true

with:

- checkout: self
  fetchDepth: 0
  persistCredentials: true

The -checkout task performs a shallow fetch in pipelines created after Septembre 2022. Since gitversion needs the full commit history to find tags, it tries and crashes. Specifying fetchDepth: 0 disable shallow fetch.

References: Gitversion, Microsoft.

Slover answered 13/1, 2023 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.