LockedFileException: failed to lock file config.lock for writing

Viewed 1238

I'm trying to run a dotnet build on my Jenkins build server. I keep getting the following error:

C:\Nuget\PackagesCache\gitversiontask\5.1.3\build\GitVersionTask.targets(10,9): error : LockedFileException: failed to lock file 'C:/jenkins/workspace/Shared-Build/.git/config.lock' for writing

And sometimes this message appear:

C:\Nuget\PackagesCache\gitversiontask\5.1.3\build\GitVersionTask.targets(10,9): error : LibGit2SharpException: failed to rename lockfile to 'C:/jenkins/workspace/Shared-Build/.git/config': Access is denied.

What interesting is that another team member can successfully run the build, without these errors appearing.

I tried to look online but no clear solution is available. This exception seems to be related to the gitversiontask Nuget package, but I'm using a fairly updated version of it. Did anyone ever encountered this error before?

2 Answers

The solution was re-creating the config and config.lock (while keeping the worktree intact).

del .git\config
del .git\config.lock

And then use this command

git reset --mixed head
Related