Automatically run a task before each step


Is there a way octopus deploy can be configured to run a certain task or step before ever step in the project?

My issue is as follows. We have a lot of developers who can access our VM’s and they sometimes leave folders/files open. So when octopus goes to purge a directory, it cannot due to the object being locked. I am looking at forcing the object to be unblocked before each step is executed.

My first thought is to create a ‘step template’ and insert that as a pre step before the execution of each step. But this might become tedious so I was hoping there might be a way octopus can automatically run a task/step when it runs every step in a project?


Thanks for reaching out. Would’n it be possible to just unlock everything on the first step instead of doing it for every single step? In case you have already thought of that, there might be a “hidden trick” that could help you with this: Check out the Gotcha in red on the document below. It explains how (almost) each step in Octopus is executed through Powershell, and if you add a Script Module with a code that’s not inside of a function, that line of code will get executed at the begging of each step.

Hope that helps!


Dalmiro… you’re a life saver. I think this might be what i’m looking for. Thanks! I’ll try it out and will reach out again if it doesn’t.

Hi Dalmiro,

I have been trying to use the script module, but i’m not sure if i’m using it properly.

I created the module as such, see the PreStep.jpg.

I added the module as such, see AddModule.jpg

I added the following to the Pre-Deploymen Script section of the step, “Say-Hello -name George”. According to what you’re saying i should also see the output which is before the function in the module. But i do not see it in my log.

Will I not see any output from the code being executed before a step? i.e. the stuff before the function in the module.

Hi Mandeep,

I just tested this again to see if something changed on our end. The code seems to be executing, but you just cant see the output from it on the deployment log. I’ve tested this by adding this line to my module:

get-date | out-file c:\Deploy\journal.txt -append

In regular script steps the line was executed as expected, and a time entry was added to C:\Deploy\Journal.txt

In NuGet Deploy steps, by default this was not executed. But if you add custom scripts to the step with something as tiny as write-output "." it will have the same result as for regular script steps.

Please understand that this is not an official feature, but rather a (good?)consequence of how we manage the Powershell steps, hence the reason why its tricky to implement.