Is it possible to execute a process' step only depending on some criteria?

Hello community. I have the following situation:

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.

Hi @edgardo.varela,

Welcome to the Octopus Forums!

Thanks for reaching out.

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.

Please let me know if that will work for you.

Thanks,
Jeremy

1 Like

I’ve implemented the use of an output variable and works just fine!
Thank you very much!

1 Like

Hey edgardo,

Thank you for updating me that it worked for you! I’m glad to hear you got it working.

Have a great rest of your week.

Thanks,
Jeremy

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.