Remove files and foldes on Azure before a new deploy from VSTS

前端 未结 3 702
野趣味
野趣味 2020-11-29 09:32

As part of my build process in VSTS I want to delete all files and folders (except af few) from my azure site before a new deploy. My guess is, that using a Azure Powershell

3条回答
  •  渐次进展
    2020-11-29 10:19

    This is how you can test your settings that you use in the PowerShell scripts above using Postman.

    I found it useful to play with the REST API using Postman to understand what the PowerShell scripts above were doing and understand what status codes I could expect back from the API. I also noticed that the recursive logic for deleting a directory returns a 409 Conflict error even though is DOES delete the files.

    In the examples below, my app service is called "YatesDeleteMe"

    Create a base 64 encoded username and password string to use below in your authorization header OR run the PowerShell scripts above and it will output one for you

    1. Download your app service's publish file, which can be downloaded from the Overview tab in the Azure portal.
    2. Open the file with a text editor
    3. Find the username (user name example: $YatesDeleteMe ) and password (password example: ch222cDlpCjx4Glq333qo4QywGPMs1cK2Rjrn6phqZ9HswtgEEE12CrhDmcn )
    4. Create a string out of them and separate them with a colon (should look something like this: $YatesDeleteMe:ch222cDlpCjx4Glq333qo4QywGPMs1cK2Rjrn6phqZ9HswtgEEE12CrhDmcn )
    5. Base 64 encode them using your own program a site. The result should look something like this: JFlhdGVzRGVsZXRlTWU6Y2gyMjJjRGxwQ2p4NEdscTMzM3FvNFF5d0dQTXMxY0syUmpybjZwaHFaOUhzd3RnRUVFMTJDcmhEbWNu

    Retrieve a single file

    1. Open Postman
    2. Change the verb to GET
    3. Enter your URL to the file you want to retrieve (e.g., https://YatesDeleteMe.scm.azurewebsites.net/api/vfs/site/wwwroot/web.config). For more info on paths see this
    4. Added a header-->
      • Key: Authorization
      • Value: Basic YourBase64EncodedStringFromAbove
    5. Left-click the "Send" button and the file will download

    Delete a single file

    1. Open Postman
    2. Change the verb to DELETE
    3. Enter your URL to the file you want to delete (e.g., https://YatesDeleteMe.scm.azurewebsites.net/api/vfs/site/wwwroot/web.config)
    4. Added a header-->
      • Key: Authorization
      • Value: Basic YourBase64EncodedStringFromAbove
    5. Added a header-->
      • Key: If-Match
      • Value: *
    6. Left-click the "Send" button and the file will deleted

    Delete all the files in a directory

    1. Open Postman
    2. Change the verb to DELETE
    3. Enter your URL to the folder you want to delete PLUST add slash and then the query string ?recursive=true (e.g., https://YatesDeleteMe.scm.azurewebsites.net/api/vfs/site/wwwroot/?recursive=true)
    4. Added a header-->
      • Key: Authorization
      • Value: Basic YourBase64EncodedStringFromAbove
    5. Added a header-->
      • Key: If-Match
      • Value: *
    6. Left-click the "Send" button and the folder will deleted. I always get a 409 error back, but the folder is deleted.

    Reference

    • Blog post with pictures here.

提交回复
热议问题