Migrate PS scripts from a package to standalone mode



We’ve developed some scripts that are stored in the root folder of a particular Visual Studio application – which get included in the deployment package:

  • PreDeploy.ps1
  • Deploy.ps1
  • PostDeploy.ps1

However we now want to make the same functionality available to multiple applications, without having to make a copy of the three scripts (thereby having to maintain multiple copies.)

I suspect that standalone scripts in a package might be the way to go. But does the naming and ordering work the same way – i.e. PreDeploy, Deploy, PostDeploy (as defined here)?

If not, what is the best way to mimic the timing of executing these scripts using standalone scripts?

(Jayden Platell) #2


I’m including my response from our email support channel here in case it can benefit others.

There are a few ways you can achieve this in Octopus.

The first is to convert the deployment step into a custom step template and embed the scripts in the template by using the “Configure features” option to enable the “Configuration Scripts” feature. This has some of the same benefits as source-controlled scripts - they are versioned and you can update them in one place.

Another option is to create a dedicated scripts package and use the “Run a script” step to execute it on the target. This has the benefit of keeping the scripts in source control, but they won’t run in the installation directory of your main package. You can use output variables to retrieve the installation directory of a step in a following step, but it is more difficult for a previous step.

You can find more information on these methods in our documentation on Custom Scripts. Hopefully one of these methods will meet your requirements.



It’s still not clear to me, so let me ask a different way.

Is it possible to duplicate the exact timing and capabilities of the PreDeploy, Deploy and PostDeploy Powershell scripts without embedding them in the package to be deployed?

(Jayden Platell) #4


Sorry for the confusion. Yes - the three script sections in the “Custom deployment scripts" feature of a deployment step are executed at the same point of the deployment process and in the same way as their corresponding scripts from within a package would. Our docs can provide more information.

Adding these scripts via a custom step template will allow you to avoid maintaining multiple copies. Otherwise, each time a script changes, it will need to be updated in every deployment step that uses it, which won’t be any better than the original problem, :slight_smile:

I hope that information is helpful. Please let me know if I can clarify anything further.



I want to avoide maintaining multiple copies, but I also need these same scripts to be used in multiple projects. How can I do that?