Octopus allows you to embed PowerShell scripts in your packages that are executed automatically during a deployment. This is a great hook that allows you to:
- Run custom executables
- Configure Windows Services
- Configure IIS
- Execute database deployment scripts
- Configure security settings of files and folders
- Tons of other things
Variables defined in the Octopus portal will be automatically passed to your scripts, and since variables can be scoped to an environment or machine, this provides a nice way to parameterize your scripts for different environments.
The Tentacle agent hosts PowerShell in-process, which means there are sometimes differences between how a script will run in normal PowerShell, versus how they run in Octopus. Testing scripts was always difficult - you'd have to package them up, create a release, and deploy the release just to see if a small change to the script worked.
If you are having trouble getting a PowerShell script to run, you can now test the scripts directly using the Tentacle executable, which means they run in exactly the same context as they do in a deployment. You can do this from the command line using:
Tentacle.exe run-script -v Message="Hello world!" -v Repeat=5 -f MyScript.ps1
The -v
argument allows you to pass variables (as if they were variables being used in the deployment). The -f
argument specifies the script file to run. You can also use -w
to set a custom working directory.
Assuming my script looked like this:
foreach ($i in (1..$Repeat))
{
write-host $Message
}
The output would look like:
This feature is available from build 1.0.16.1276. Hopefully it makes testing PowerShell scripts in a Tentacle context easier!
Learn more
- PowerShell and IIS: 20 Practical Examples
- Configuration Management with Octopus and PowerShell DSC
- Documentation: Custom Scripts
- Documentation: Running an Azure PowerShell script step