如何在使用TeamCity通过SMB上传文件之前从远程文件夹中删除所有内容

问题描述 投票:0回答:1

我在Windows机器上运行TeamCity服务器和代理。我在构建过程中的最后一步是通过SMB将bin / release字段上传到另一台服务器上的共享Windows文件夹。

我需要在上传新版本之前删除远程服务器上的所有文件,但无法找到方法。

我在SMB上传跑步者中没有看到任何此类选项。

windows teamcity smb
1个回答
1
投票

是的,你是正确的,应该作为构建步骤下的一步添加,我更喜欢这样的powershell命令

robocopy \\%WebServer1%\%SourceFolder% \\%WebServer1%\%DestinationFolder% /E /PURGE /IS /COPY:DT /R:1 /W:2
RMDir /S "%WebServer1%\%SourceFolder%

Where, 
    /E - Copies sub directories
    /PURGE - Deletes destination files and directories that no longer exist in the source
    /COPY:DT - Specifies the file properties to be copied, in this case it copies Data and Timestamps
    /R:1 - Specifies the number of retries on failed copies, in this case it is 1
    /W:2 - Specifies the wait time between retries, in seconds, in this case it is 2 seconds
    /s - Includes subdirectories

一旦robocopy成功,RmDir将删除源目录。

如果您需要直接删除文件而不是复制然后删除,则可以使用Move

移动参考 - https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/move

我个人更喜欢复制和删除

© www.soinside.com 2019 - 2024. All rights reserved.