如何在使用 TeamCity 通过 SMB 上传文件之前删除远程文件夹中的所有内容
How to delete all content from remote folder before uploading files through SMB with TeamCity
我是 运行 Windows 机器上的 TeamCity 服务器和代理。我在构建过程中的最后一步是通过 SMB 将归档的 bin/release 上传到另一台服务器上的共享 Windows 文件夹。
我需要在上传新版本之前删除远程服务器上的所有文件,但我想不出办法。
我在 SMB 上传程序中没有看到任何此类选项。
是的,你是对的,应该作为构建步骤下的一个步骤添加,我更喜欢这样的 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
我个人更喜欢复制和删除
我是 运行 Windows 机器上的 TeamCity 服务器和代理。我在构建过程中的最后一步是通过 SMB 将归档的 bin/release 上传到另一台服务器上的共享 Windows 文件夹。
我需要在上传新版本之前删除远程服务器上的所有文件,但我想不出办法。
我在 SMB 上传程序中没有看到任何此类选项。
是的,你是对的,应该作为构建步骤下的一个步骤添加,我更喜欢这样的 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
我个人更喜欢复制和删除