简体   繁体   中英

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.

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)

Is there any way to do this in Azure Pipelines?

Here you can take a look at a Catalog of the built-in tasks for 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."

That is correct for default behavior, but it has a parameter called SourceFolder, which has a default as "$(Build.SourcesDirectory)". When you specify the SourceFolder to be "C:" you can enter a pattern to delete anything on the server. Might be wiser to use a bit more elaborate path then just c:\ but it works. Just tried it on a pipeline where a file needed to be deleted not from the workingfolder but from the deployed IIS location.

PS in a release pipeline the default seems to be the $(System.DefaultWorkingDirectory) and not the $(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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