Octopus Deploy Documentation

Passing Parameters to Scripts

Last updated

Octopus can pass parameters to your custom script files for any of the supported scripting languages. This means you can use existing scripts, or write and test your own parameterized scripts that have no knowledge of Octopus, passing Octopus Variables directly to your scripts as parameters. The Octopus scripting API is still available within the context of your script, meaning you can use a mixture of parameters and other Octopus variables and functions.

Consider this example PowerShell script:

PowerShell script using Octopus Variables

$environment = $OctopusParameters["Octopus.Environment.Name"]
Write-Host "Environment: $environment"

You can parameterize this script making it easier to test outside of Octopus:

PowerShell script using parameters

param (
Write-Host "Environment: $Environment"

When you call external scripts (sourced from a file inside a package) you can pass parameters to your script. This means you can write "vanilla" scripts that are unaware of Octopus, and test them in your local development environment.

You can define your parameters in the Script Parameters field using the format expected by your scripting execution environment (see below for examples).

Script Parameters

Delimiting string values
Don't forget to correctly delimit your parameters correctly for the scripting engine. In the example above we have surrounded the parameter value in double-quotes to handle cases where the Environment Name has spaces: "#{Octopus.Environment.Name}"

Passing Parameters to PowerShell Scripts

You can pass parameters to PowerShell scripts as if you were calling the script yourself from PowerShell, using positional or named parameters.

Script Parameters in Octopus

-Environment "#{Octopus.Environment.Name}" -StoragePath "#{MyApplication.Storage.Path}"

Usage in PowerShell script

Param (
Write-Host "$Environment storage path: $StoragePath"

Passing Parameters to C# Scripts

You can pass parameters to C# scripts as described here for the ScriptCS engine. ScriptCS only supports positional parameters.

Script Parameters in Octopus

-- "#{Octopus.Environment.Name}" "#{MyApplication.Storage.Path}"

Usage in C# script

var environment = Env.ScriptArgs[0]
var storagePath = Env.ScriptArgs[1]
Console.WriteLine("{0} storage path: {1}", environment, storagePath);

Passing Parameters to Bash Scripts

You can pass parameters to Bash scripts as described in Bash manual.

Script Parameters in Octopus

"#{Octopus.Environment.Name}" "#{MyApplication.Storage.Path}"

Usage in Bash script

echo "$environment storage path: $storagePath"

Passing Parameters to F# Scripts

You can pass parameters to FSharp scripts as described in MSDN.

Script Parameters in Octopus

"#{Octopus.Environment.Name}" "#{MyApplication.Storage.Path}"

Usage in F# script

let environment = fsi.CommandLineArgs.[1]
let storagePath = fsi.CommandLineArgs.[2]
printfn "$s storage path: $s" environment storagePath

Usage in Python3 script

print("Parameters {} {}".format(environment, storagePath))

Welcome! We use cookies and data about how you use our website allow us to improve the website and your experience, and resolve technical errors. Our website uses cookies and shares some of your data with third party analytics companies for these purposes.

If you decline, we will respect your privacy. A single cookie will be used in your browser to remember your preference.