actions: [ISSUE]: gitversionexecute returning `Output: undefined` because `GitVersion output is not valid JSON`
Prerequisites
- I have written a descriptive issue title
- I have searched issues to ensure it has not already been reported
GitVersion package
AzureDevops task
GitVersion version
6.x
Operating system
Windows
What are you seeing?
I’m running gitversion on a local Azure Pipelines agent:
steps:
- checkout: self
fetchDepth: 0
clean: true
- task: gitversion/setup@3
inputs:
versionSpec: '6.x'
- task: gitversion/execute@3
inputs:
useConfigFile: true
configFilePath: GitVersion.yml
and getting this unhelpful output in the gitversion/execute task:
Starting: gitversionexecute
==============================================================================
Task : Execute GitVersion Task
Description : Easy Semantic Versioning (https://semver.org/) for projects using Git
Version : 3.2.0
Author : GitTools Contributors
Help : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Command: git -C C:\myagent\_work\5\s rev-parse --is-shallow-repository
Command: C:\myagent\_work\_tool\GitVersion.Tool\6.2.0\dotnet-gitversion.exe --roll-forward Major C:\myagent\_work\5\s /output json /l console /config C:\myagent\_work\5\s\GitVersion.yml
##[error]GitVersion output is not valid JSON
dotnet-gitversion Output:
-------------------
undefined
-------------------
undefined
Finishing: gitversionexecute
When remoting in to that agent, and running that command C:\myagent\_work\_tool\GitVersion.Tool\6.2.0\dotnet-gitversion.exe --roll-forward Major C:\myagent\_work\5\s /output json /l console /config C:\myagent\_work\5\s\GitVersion.yml, it gives a more helpful error message:
INFO [25-04-02 8:53:58:81] Applicable build agent found: 'LocalBuild'.
INFO [25-04-02 8:53:58:88] Working directory: C:\myagent\_work\5\s
ERROR [25-04-02 8:53:59:04] An unexpected error occurred:
LibGit2Sharp.LibGit2SharpException: repository path 'C:/myagent/_work/5/s/' is not owned by current user
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 154
at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 172
at LibGit2Sharp.Core.Proxy.git_repository_open(String path) in /_/LibGit2Sharp/Core/Proxy.cs:line 2560
at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter) in /_/LibGit2Sharp/Repository.cs:line 159
at LibGit2Sharp.Repository..ctor(String path) in /_/LibGit2Sharp/Repository.cs:line 70
at GitVersion.Git.GitRepositoryInfo.GetProjectRootDirectory() in /_/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 90
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at GitVersion.Git.GitRepositoryInfo.get_ProjectRootDirectory() in /_/src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs:line 33
at GitVersion.GitPreparer.Prepare() in /_/src/GitVersion.Core/Core/GitPreparer.cs:line 39
at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in /_/src/GitVersion.Core/Core/GitVersionCalculateTool.cs:line 35
at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in /_/src/GitVersion.App/GitVersionExecutor.cs:line 69
INFO [25-04-02 8:53:59:05] Please run `git log --graph --format="%h %cr %d" --decorate --date=relative --all --remotes=*` to see the git graph. This can help you troubleshoot any issues.
Steps to Reproduce
Seems to be related to safe directories?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 16 (1 by maintainers)
Taking in consideration this is mostly a git security issue, I will close this issue
I encountered the same issue. Here’s what I did to fix our deployment pipeline:
@dazinator Could you please share versioning by using dotnet tool
It’s definitely because of the “new”/l consoleparameter being passed. Since that will print non-JSON (basically all the other verbose logging information) and Github Actions will fail to parse the step’s output with the error everyone is seeing.~~Looks like the damage was done in v3.0.4 release. Every release after that will be unusable as step output in GHA. https://github.com/GitTools/actions/commit/bc3a4702bbcaaa41f1c40bc460bd72916fc1657e~~
The issue seems quite unrelated to
/l console. There is actually a deeper git error bubbling up, which is causing GitVersion to emit non-JSON output (printing the error), which then breaks the GHA.Looking slightly into this, it seems like LibGit2Sharp is simply re-emitting an error from libgit2 itself. Which is probably around allowing root execute for git operations. There are some notes in LibGit2Sharp about disabling such restrictions in codebase with:
Trying to test if the above does fix GitVersion.
The only currently workable solution is to manually add
safe.directory = *to the user’s .gitconfig. For some reason theset-safe-directoryinput parameter inactions/checkoutonly adds the workspace to a .gitconfig in a TEMP homedir, which is no longer used after that checkout. So becomes almost meaningless almost I am misunderstanding something. Checking simple file permissions shows the root user fully owns everything in the GITHUB_WORKSPACE directory. The user is in fact root (whoami). Without manually adding the safe.directory path LibGib2Sharp seems to always throw that exception, which then breaks all of GitVersion. Possibly only relevant in newer versions of GitVersion when they bumped their LibGit2Sharp dependency.Working set of steps.