iisazure-devopsdevops

IIS WEB APP MANAGE - CLEAR recycling.periodicRestart.schedule


I am trying to set some App pool configurations using appcmd.exe commands!

I have command to set the periodic recycling like this:

set config -section:system.applicationHost/applicationPools /+"[name='AppPoolName'].recycling.periodicRestart.schedule.[value='19:05:00']" /commit:apphost

It works fine the first time - but when we do redeploy it fails due to the existing periodic recycle value.

How can I first clear all values in periodic recycling scheduler using appcmd.exe ? Or if someone has solution to skip this command ?


Solution

  • I can reproduce the similar issue when using the same appcmd.exe command to set the periodic recycling.

    enter image description here

    How can I first clear all values in periodic recycling scheduler using appcmd.exe ?

    You can use the following command to remove the existing periodic recycling value : change /+ to /-

    set config -section:system.applicationHost/applicationPools /-"[name='AppPoolName'].recycling.periodicRestart.schedule.[value='19:08:00']" /commit:apphost
    

    To use the commands in the IIS Web deploy task, you can refer to the following sample:

    steps:
    - task: IISWebAppManagementOnMachineGroup@0
      displayName: 'IIS Web App Manage'
      inputs:
        WebsiteName: 'Default Web Site'
        AddBinding: True
        Bindings: '{"bindings":[{"protocol":"http","ipAddress":"All Unassigned","port":"80","hostname":"","sslThumbprint":"","sniFlag":false}]}'
        CreateOrUpdateAppPoolForWebsite: true
        AppPoolNameForWebsite: AppPoolName
        ParentWebsiteNameForVD: 'Default Web Site'
        ParentWebsiteNameForApplication: 'Default Web Site'
        AppCmdCommands: |
         set config -section:system.applicationHost/applicationPools /-"[name='AppPoolName'].recycling.periodicRestart.schedule.[value='19:08:00']" /commit:apphost
         set config -section:system.applicationHost/applicationPools /+"[name='AppPoolName'].recycling.periodicRestart.schedule.[value='19:08:00']" /commit:apphost
    

    Classic Pipeline:

    enter image description here

    Result:

    enter image description here

    UPDATE: To remove all elements in collection:

    clear config  /section:applicationPools  /[name='AppPoolName'].recycling.periodicRestart.schedule