Running step once on Octopus Server with tenant deployment


Is it possible to run a PowerShell script once, on the Octopus server? This is needed when the deployment contains a match for at least one of those specified in “on behalf of target roles” and deploying to a tenant environment.

The documentation at does not help with this scenario because it does not consider tenants. I don’t want to make the Octopus server part of every tenant environment.

The issue I have at the moment, is my step will run on the Octopus server but at least once for every role I have specified in “on behalf of target roles”. This causes conflicts as I have to use a rolling deployment to avoid this.


Hi Blair,

That documentation is a little out-dated now. As you are aware, you can now set a script step to “Run on: Octopus Server”.

If you leave ‘On behalf of target roles’ empty, the script will execute just once on the Octopus Server. The catch is, it will always execute, regardless of which roles are being deployed to.

The idea of running a step once on the Octopus Server, but only if a particular role is contained in the deployment, is not one we cater for out-of-the-box.

The best we can think to suggest here is to set your step to ‘Run on: Octopus Server’ and ‘On behalf of target roles’ to the roles you are interested in. And to then implement the lock yourself using a file.

You would need to be able to determine a unique file-location based on whatever constraints you need (e.g. tenant, release, role, etc - all of which are available as variables to your script). Once you have that location, check if the file exists. If it does, your script has already been run. If not, attempt to create it (failing if it has already been created), and then execute your script.

What do you think?


Hi Michael,

Thank-you for your quick reply.

I think my issue was that I had a child step which required roles to be supplied. I could re-implement this such that I separate out the child step into it’s own separate step. This way I can have one step which does not have target roles and runs on the Octopus server and the other which has roles and runs on the targets. It should only require some refactoring and small changes in my code.