简体   繁体   English

使用TFS构建/发布定义从远程服务器删除文件

[英]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 要删除远程路径中的文件,可以使用“ 远程删除”任务

Like this 像这样 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过TFS发行版Build Definition在Build Server上运行Windows应用程序 - Run Windows application on Build Server by TFS Release Build Definition 从版本定义触发TFS构建时出现未授权错误 - Getting Unauthorised error while triggering TFS build from release definition 如何在TFS中使用PowerShell获取当前的构建定义名称 - How to get current Build definition name using PowerShell in TFS TFS构建定义秘密变量 - TFS Build Definition Secret Variables 用于构建 TFS 定义的 PowerShell 脚本 - PowerShell Script to Build TFS Definition 仅作为TFS构建的一部分从TFS中检入文件 - Get only checked in files from TFS as part of TFS build 从TFS 2015动态读取远程VSTS Build ID - Read remote VSTS Build id dynamically from TFS 2015 从TFS生成错误运行PowerShell远程重启服务 - PowerShell remote restart service running from a TFS build error 目标机器上的TFS2015 Powershell-在发布过程中设置变量/在远程服务器上找到可用端口 - TFS2015 Powershell on Target Machine - Set a variable in the release process / Find a free port on a remote server 使用Windows PowerShell删除远程Windows Server中早于x天的文件和文件夹 - Delete files and folders older than x days in remote windows server using windows powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM