質問: $octopusparameters['apppoolname'] if ( (get-webapppoolstate -name $apppoolname).value -eq "stopped" ) { write-host "apppool already stopped: " + $apppoolname } else { write-host "shutting down the apppool: " + $apppoolname write-host (get-webapppoolstate $apppoolname).value # signal to stop. stop-webapppool -name $apppoolname } do { write-host (get-webapppoolstate $apppoolname).value start-sleep -seconds 1 } until ( (get-webapppoolstate -name $apppoolname).value -eq "stopped" )
回答: octopus deployにはいくつかのコミュニティpowershellスクリプトがあり、ここで確認できます https://library.octopus.com/listing これは、再試行するそれらの1つの内容です。# load iis module: import-module webadministration # get apppool name $apppoolname = $octopusparameters['apppoolname'] # get the number of retries $retries = $octopusparameters['apppoolcheckretries'] # get the number of attempts $delay = $octopusparameters['apppoolcheckdelay'] # check if exists if(test-path iis:\apppools\$apppoolname) { # stop app pool if not already stopped if ((get-webapppoolstate $apppoolname).value -ne "stopped") { write-output "stopping iis app pool $apppoolname" stop-webapppool $apppoolname $state = (get-webapppoolstate $apppoolname).value $counter = 1 # wait for the app pool to the "stopped" before proceeding do{ $state = (get-webapppoolstate $apppoolname).value write-output "$counter/$retries waiting for iis app pool $apppoolname to shut down completely. current status: $state" $counter++ start-sleep -milliseconds $delay } while($state -ne "stopped" -and $counter -le $retries) # throw an error if the app pool is not stopped if($counter -gt $retries) { throw "could not shut down iis app pool $apppoolname. `ntry to increase the number of retries ($retries) or delay between attempts ($delay milliseconds)." } } else { write-output "$apppoolname already stopped" } } else { write-output "iis app pool $apppoolname doesn't exist" } これはこのライブラリテンプレートに由来します https://library.octopus.com/step-templates/3aaf34a5-90eb-4ea1-95db-15ec93c1e54d/actiontemplate-iis-apppool-stop