Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity NuGet Installer step fails

This error occurs sometimes, usually this step works fine, but in about 10% cases it fails with below message.

Nuget installer step is first build step, and also "clean checkout" is enabled in TeamCity, so there shouldn't be any process that uses file.

[restore] The process cannot access the file 'C:\BuildAgent\work...\packages\Microsoft.Bcl.Build.1.0.21\Microsoft.Bcl.Build.1.0.21.nupkg' because it is being used by another process.

[restore] Process exited with code 1

like image 644
Lev Avatar asked Feb 01 '16 10:02

Lev


3 Answers

Root cause of "my file is being used by another process"

There are several things you can do, depending on what is the root cause:

  • You use parallel build feature of MSBuild: According to his blog, It seems to not work well with NuGet package restore, because it could runs parallel package restore for each projects (and if several projects require Microsoft.Bcl.Build... Boom!). Either disable parallel build or do package restore outside of solution (in a command line step). By the way, it's not a good practice to do NuGet restore with solution MSBuild.

  • There is another process:
    Use process monitor/explorer to find out which process hold the lock on the file. It could be an antivirus, file indexing tool, an additional build agent instance which keep running in the background. As the lock is not permanent, and 1 out of 10 is quite a lot for this kind of issue, I would not bet that this is the root cause.

  • There is no other process:
    It's a bug in the Teamcity NuGet installer which do something. Then you could replace the step by a command line step with a call to nuget restore and check if it fixes your problem.

  • Diagnose yourself with a nuget plugin of your flavor:
    NuGet plugin code is available here. It means you can compile a version of your own, with additional debugging information when these kind of problem happen (list of process locking the file for example). Or even more useful, you can add a retry step in case the file is locked.

EDIT: For those who use Teamcity on Unix...

I've tried to install Teamcity on Unix and make a build on mono with the NuGet plugin. By the way, NuGet plugin does not work at all on Unix (It's not supported by JetBrains). I even tried to fix it but it was easier to just replace it with a command line.

like image 82
Fab Avatar answered Oct 23 '22 15:10

Fab


Do you have separate working directory for each build agent? Otherwise two paralel builds could execute in the same time.

like image 3
mano Avatar answered Oct 23 '22 15:10

mano


Try this:

  1. Add a special build step in TeamCity which runs if "Even if some of the previous steps failed". (https://confluence.jetbrains.com/display/TCDL/Configuring+Build+Steps)
  2. In this build step find out which process is locking a file and print it in log. (How do I find out which process is locking a file using .NET?)
like image 2
Dmitrii Zyrianov Avatar answered Oct 23 '22 15:10

Dmitrii Zyrianov