I need to set a process’ step that executes only if certain WebApp exists in my IIS. Is there a way to achieve this?
A possible workaround that I’m thinking of is to create a powershell script that verifies and creates the WebApp and AppPool, but it would be much much better if I can have this process’ step as default and “turn it off” if the WebApp already exists.
Example:
WebApp does not exist
Step 1: Check if WebApp “Example” exists WebApp “Example” doesn’t exist, so step 2 will be executed
Step 2: Create WebApp “Example”
Step 3, Step 4 and so on.
WebApp exists
Step 1: Check if WebApp “Example” exists WebApp “Example” exists, so step 2 won’t be executed
Step 3, Step 4 and so on.
I think you’re on the right track. I have a couple suggestions depending on how you want to implement it.
Method 1: Have a separate step that checks for the webapp, then creates an output variable and sets it to True. Have the deploy webapp step Run Condition based on this output variable. The downside to this is you will have 2 steps, the upside is it will skip the step entirely meaning the package will not be sent to the target at all.
Method 2: Have a pre-deployment script enabled within the deploy to IIS step that has your “If WebApp “Example” exists” logic, then short circuit the rest of the step if it does.
To enable pre-deployment scripts, within the step click Configure Features toward the bottom, then enable Custom Deployment Scripts. Within your pre-deployment script block, you will put your logic there and then short-circuit the step using Set-OctopusVariable -name ‘Octopus.Action.SkipRemainingConventions’ -value ‘True’ as seen at the bottom of that documentation.
The downside to this method would be that I believe the package will get sent to the target even before the pre-deployment script is run, but the upside is the logic is all self contained in one step.