[英]Delete files from remote server using TFS build/release definition
I am using TFS v2015 to deploy a web application to a remote server. 我正在使用TFS v2015将Web应用程序部署到远程服务器。 Due to the way our project is structured (as a web site project) the build ends up creating a separate DLL for each .cs.
由于我们项目的结构方式(作为网站项目),构建最终为每个.cs创建了一个单独的DLL。 The names of the DLL files are random and change on each deploy.
DLL文件的名称是随机的,并且在每次部署时都会更改。 This has resulted in 25,000+ files in the bin folder with names like "App_Web_0bbazvic.dll".
这导致bin文件夹中的文件超过25,000个,名称类似于“ App_Web_0bbazvic.dll”。
What I would like to do is, before copying files to target machine, delete all files matching the pattern "/bin/app_code_*.dll" from the remote bin directory. 我想做的是,在将文件复制到目标计算机之前,从远程bin目录中删除所有与模式“ /bin/app_code_*.dll”匹配的文件。
I have considered using the "Machine File Copy" with the option "clean target" enabled, but I don't want to delete the entire directory. 我已经考虑过使用启用了“清除目标”选项的“机器文件复制”,但是我不想删除整个目录。 I can explain my reasons for this in more detail if requested.
如果需要,我可以详细解释我的原因。
I am also considering the "Power Shell on Target Machine" task. 我也在考虑“目标计算机上的Power Shell”任务。 Any suggestions would be appreciated.
任何建议,将不胜感激。 Also, the remote server is not in the same domain as the build agent.
另外,远程服务器与构建代理不在同一域中。
You can add something like this as an inline script if you are able to use WinRM. 如果能够使用WinRM,则可以将类似的内容添加为内联脚本。
Get-ChildItem -Path C:\Path\To\Files -recurse -include app_code_*.dll | Remove-item
https://docs.microsoft.com/en-us/vsts/pipelines/tasks/deploy/powershell-on-target-machines?view=vsts https://docs.microsoft.com/en-us/vsts/pipelines/tasks/deploy/powershell-on-target-machines?view=vsts
You can do this using simple Delete Task without even going to PowerShell assuming your files are located the same location where the agent is running. 您可以使用简单的“ 删除任务”来执行此操作,甚至无需假设您的文件位于代理运行所在的相同位置,甚至无需使用PowerShell。
Like this 像这样
For deleting files in remote path you can use the Remote delete task 要删除远程路径中的文件,可以使用“ 远程删除”任务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.