Search code examples
azure-devopspipelinegitversionazure-yaml-pipelines

Azure DevOps pipeline task `task: gitversion/execute@0` fails with unexpected error "##[error]SyntaxError: Unexpected end of JSON input"


I was running the pipeline with a simple task to install the git and check the version by the following tasks.

Everything was running well till the time I created another temporary pipeline with the same yaml file for some additional tests and development.

I did not change anything from the yaml file which is running green still, with the same tasks.

But the execute task in the new pipeline fails with an 'unexpected' error

  steps:
    - task: gitversion/setup@0
      displayName: Install GitVersion
      inputs:
        versionSpec: "5.10.x"
    
    - task: gitversion/execute@0
      displayName: Determine Version
      inputs:
        useConfigFile: true
        configFilePath: ./gitversion.yml

The output looks like this:


Command: dotnet-gitversion /agent/_work/26/s /output json /output buildserver /config /agent/_work/26/s/gitversion.yml
/opt/hostedtoolcache/GitVersion.Tool/5.10.3/x64/dotnet-gitversion /agent/_work/26/s /output json /output buildserver /config /agent/_work/26/s/gitversion.yml
  ERROR [09/20/22 12:54:22:24] 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)
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(Int32 recursions, IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 77
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfigurationInternal(Int32 recursions, IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 54


....
System.NullReferenceException: Object reference not set to an instance of an object.
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
   at LibGit2Sharp.Core.Handles.ObjectHandle.op_Implicit(ObjectHandle handle) in /_/LibGit2Sharp/Core/Handles/Objects.cs:line 509
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
   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 GitVersion.VersionCalculation.NextVersionCalculator.get_context() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 15
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\VersionCalculation\NextVersionCalculator.cs:line 30
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 52
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\GitVersion\GitVersion\src\GitVersion.App\GitVersionExecutor.cs:line 66
  INFO [09/20/22 9:44:27:78] Attempting to show the current git graph (please include in issue): 
  INFO [09/20/22 9:44:27:78] Showing max of 100 commits
  INFO [09/20/22 9:44:27:80] * 03932e8 2 hours ago  (grafted, HEAD -> feature/legok8sdeploy, origin/03932e8129e442c335e9ffd69a88b0ce4df3a3f0, 03932e8129e442c335e9ffd69a88b0ce4df3a3f0)

  INFO [09/20/22 9:44:27:82] Done writing 
##[error]SyntaxError: Unexpected end of JSON input

The error doesn't seem to be very intuitive.

I could find a GitHub issue opened here:

https://github.com/GitTools/GitVersion/issues/3081

But this doesn't give any solution to resolve and make the task green again.

Note: I'm running it from my branch and not main.


Solution

  • The cause of the issue could be related to the fetch depth of the Pipeline repo.

    By default, the Shallow fetch of the pipeline repo is 1 by default.

    You can try to set the fetchDepth to 0 in YAML Pipeline.

    For example:

    steps:
        - checkout: self
          fetchDepth: 0
        - task: gitversion/setup@0
          displayName: Install GitVersion
          inputs:
            versionSpec: "5.10.x"
        
        - task: gitversion/execute@0
          displayName: Determine Version
          inputs:
            useConfigFile: true
            configFilePath: ./gitversion.yml
    

    Or you can navigate to YAML Pipeline -> ... -> Triggers -> YAML -> Get sources -> Shallow fetch. You can unselect the option.

    enter image description here

    enter image description here