TeamCity - FTP Upload to Azure fails

2019-07-28 18:33发布

I am trying to deploy a .Net Core 2.0 project to an Azure web app using a TeamCity build.

There are 3 steps :
1 - Nuget Restore
2 - dotnet publish
3 - FTP Upload

After step 2, I get a folder "Output" with all the stuff I need to copy to my Azure web app.
I configured step 3 to copy the content from this folder to my wwwroot folder on the Azure FTP. This step copies 3 DLLs and then displays the following message :

[Step 3/3] Deployment problem: Failed to upload artifacts via FTP. Reply was: 550 The process cannot access the file because it is being used by another process.

Here is the configuration :

enter image description here

Here are the logs on the agent :

[Step 3/3] Uploaded [C:\BuildAgent\work\Output\MyLib\AutoMapper.Net4.dll] (28 KB)
[Step 3/3] > TYPE I
[Step 3/3] < 200 Type set to I.
[Step 3/3] > PASV
[Step 3/3] < 227 Entering Passive Mode (137,135,184,233,39,161).
[Step 3/3] > STOR AutoMapper.dll
[Step 3/3] < 125 Data connection already open; Transfer starting.
[Step 3/3] < 226 Transfer complete.
[Step 3/3] > CWD /site/wwwroot
[Step 3/3] < 250 CWD command successful.
[Step 3/3] Uploaded [C:\BuildAgent\work\Output\MyLib\AutoMapper.dll] (163 KB)
[Step 3/3] > TYPE I
[Step 3/3] < 200 Type set to I.
[Step 3/3] > PASV
[Step 3/3] < 227 Entering Passive Mode (137,135,184,233,39,168).
[Step 3/3] > STOR MyLib.PrecompiledViews.dll
[Step 3/3] < 550 The process cannot access the file because it is being used by another process. 
[Step 3/3] Deployment problem: Failed to upload artifacts via FTP. Reply was: 550 The process cannot access the file because it is being used by another process. 
[Step 3/3] Step Copy to Azure (FTP Upload) failed

I tried to upload the files using FileZilla and everything was ok so I guess the issue is on the TeamCity side.

1条回答
Juvenile、少年°
2楼-- · 2019-07-28 19:00

You have to stop Azure app first:

az login --username %AZURE_OWNER_ACCOUNT% --password %AZURE_OWNER_PASSWORD% --tenant %AZURE_TENANT_ID%
az webapp stop --name %AZURE_APP% --resource-group %AZURE_RESOURCE_GROUP% --subscription %AZURE_SUBSCRIPTION_ID%

Then do FTP upload (your "Copy to Azure" step above), then start the app back:

az login --username %AZURE_OWNER_ACCOUNT% --password %AZURE_OWNER_PASSWORD% --tenant %AZURE_TENANT_ID%
az webapp start --name %AZURE_APP% --resource-group %AZURE_RESOURCE_GROUP% --subscription %AZURE_SUBSCRIPTION_ID%

Just fulfill the parameters in the TeamCity project and you're ready to go

P.S. Sometimes you have to wait a bit after the "stop" attempt, as the thing is async

P.P.S. It may be required to join both "az" commands into one-liner script due a bug in Azure CLI tools (as they can fail silently after successfully executing very first az command if run under non-interactive account like SYSTEM), so you could do "az login && az stop" and "az login && az start" accordingly.

P.P.P.S. https://docs.microsoft.com/en-us/cli/azure/install-azure-cli

查看更多
登录 后发表回答