简体   繁体   English

Azure 管道在 IIS 发布后删除文件并重命名

[英]Azure Pipelines delete files and rename after IIS publish

Using Azure Build Pipelines i'm trying to publish an ASP.NET WebForms website to IIS.使用 Azure 构建管道,我正在尝试将 ASP.NET WebForms 网站发布到 IIS。

Everything works, except that I have several images in a folder of my website (eg /Images/1.jpg,2.jpg , etc..) and I would like to delete all images from that folder except 2.jpg and rename it to 1.jpg after I've deployed the website (or during the release pipeline if that's possible)一切正常,除了我网站的文件夹中有几张图片(例如/Images/1.jpg,2.jpg等),我想从该文件夹中删除除2.jpg之外的所有图片并重命名在我部署网站之后(或者如果可能的话,在发布管道期间)到1.jpg

Is there any way to do this in Azure Pipelines?在 Azure 管道中有什么办法可以做到这一点吗?

Here you can take a look at a Catalog of the built-in tasks for build-release .在这里,您可以查看build-release 的内置任务目录

The Delete Files task states: "Use this task in a build or release pipeline to delete files or folders from the agent working directory". 删除文件任务状态:“在构建或发布管道中使用此任务从代理工作目录中删除文件或文件夹”。

This may give you some ideas on how to achieve this.这可能会给你一些关于如何实现这一点的想法。 I hope this help.我希望这会有所帮助。

Comment on:给某事物发表意见:

The Delete Files task states: "Use this task in a build or release pipeline to delete files or folders from the agent working directory".删除文件任务声明:“在构建或发布管道中使用此任务以从代理工作目录中删除文件或文件夹”。 and ".. from what I just tried, this can only delete files inside the artifact and not on the IIS Server."和“..从我刚刚尝试的情况来看,这只能删除工件内的文件,而不能删除 IIS 服务器上的文件。”

That is correct for default behavior, but it has a parameter called SourceFolder, which has a default as "$(Build.SourcesDirectory)".这对于默认行为是正确的,但它有一个名为 SourceFolder 的参数,其默认值为“$(Build.SourcesDirectory)”。 When you specify the SourceFolder to be "C:" you can enter a pattern to delete anything on the server.当您将 SourceFolder 指定为“C:”时,您可以输入一个模式来删除服务器上的任何内容。 Might be wiser to use a bit more elaborate path then just c:\ but it works.使用比 c 更复杂的路径可能更明智:\ 但它有效。 Just tried it on a pipeline where a file needed to be deleted not from the workingfolder but from the deployed IIS location.只是在一个管道上尝试了它,其中一个文件不是从工作文件夹中删除,而是从部署的 IIS 位置删除。

PS in a release pipeline the default seems to be the $(System.DefaultWorkingDirectory) and not the $(Build.SourcesDirectory). PS 在发布管道中默认似乎是 $(System.DefaultWorkingDirectory) 而不是 $(Build.SourcesDirectory)。 Whether that is because the Build.SourcesDirectory defaults to System.DefaultWorkingDirectory in release pipelines or the task is being smart I don't know.我不知道这是因为 Build.SourcesDirectory 在发布管道中默认为 System.DefaultWorkingDirectory 还是任务很聪明。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM