1
votes

I m running MSBuild script to compile my project and iv set a artifact path in the general settings of TeamCity. My MSBuild scripts first build and then creates a zip file. I would like to add that zip file as a artifact but when i run the build on TeamCity i get this error:

[17:44:56]: [CreateNightlyZip] Zip
[17:44:56]: [Zip] C:\BuildAgent\Build\Build.proj(55, 5): The process cannot access the file 'C:\BuildAgent\work\c13cf8f192b25cd1\bin\Debug\20120109_Foo.PE.zip' because it is being used by another process.

So it lookes like TeamCity tries to grab the zip file right when its created and then my MSBuild script fails to put files into it.

Here is the MSBuild target:

 <Target Name="CreateNightlyZip">
    <PropertyGroup>
      <StringDate>$([System.DateTime]::Now.ToString('yyyyMMdd'))</StringDate>
    </PropertyGroup>
    <ItemGroup>
      <DebugApplicationFiles Include="$(DebugPath)\**\*.*" Exclude="$(DebugPath)\*vshost.exe*" />
    </ItemGroup>
    <MakeDir Directories="$(NightlyBuildPath)"/>
    <Zip Files="@(DebugApplicationFiles)"
      WorkingDirectory="$(DebugPath)"
      ZipFileName="$(NightlyBuildPath)\$(StringDate)_$(NightlyZipName).zip"
      ZipLevel="9" />
  </Target>

Have anybody had this problem allso or what should be solution for this?

EDIT: What is strange is that when i create zip file in the root of checkout folder then everything works, but when i create it to the Debug folder then i get this error.

2

2 Answers

2
votes

TeamCity publishes artifacts only when all build steps are finished, i.e. when MSBuild script finishes.

To publish artifacts during the build you need to produce special service message from the build script when artifacts are ready: http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-PublishingArtifactswhiletheBuildisStillinProgress

If you do not use service messages, you should check which process locked the file. Maybe you have two agents on the same machine running builds simultaneously and interfering with each other?

1
votes

What i ended up doing is not to place the created .zip file into the debug folder and just to the project root folder. Doing that the zip file is created and Teamcity is able to use it as artifact.