F# Parameters in Custom step template

I have a Custom Step Template with script source set to source code, with the script in f# but I cannot find anyway to get the parameters passed through. I have a parameter setup called Site, which displays in the parameters tab as #{Site}

If I do (which is what you get when you pick the variable via the picker tool)
Script.fsx(7,26): error FS0039: The value or constructor ‘Site’ is not defined

Outputs ‘#{Site}’ i.e. just the literal string

Script.fsx(3,34): error FS0039: The value, constructor, namespace or type ‘Parameters’ is not defined

What is the syntax to pass parameters into an fsharp script?

Hi Ian, thanks for reaching out.

You can find more information on using variables in F# scripts at https://octopus.com/docs/deploying-applications/custom-scripts#Customscripts-Variables.

For example:

System.Console.WriteLine(Octopus.findVariable "Site") 

Matt C


Thanks for you help, I’ve managed to get this working but just a couple of things to note, as you seem to be an employee:

I’ve just tested on Octopus 3.14.1592.

The first example:
Just outputs the literal ‘#{Site}’ rather than the value of the variable. So I may have found a bug. I’ve exported my step and attached it to help with any replication.

The second example:
System.Console.WriteLine(Octopus.findVariable “Site”)
However, this function is not mentioned in the linked documentation, so would be good to update it to include this.



exported.txt (990 Bytes)

*The above should say the second example works

Hi Ian. Thanks for the feedback on the docs.

The literal #{Site} will be printed if the variable is not defined or available. In your test System.Console.WriteLine("#{Site}") printed the literal while System.Console.WriteLine(Octopus.findVariable "Site") printed the variable with no other changes to the script? If so that is definitely a bug. In that case could you also attach a screenshot of the variables page?

Matt C


I deleted my original test, so have created another replicating the issue with screenshots of the input and output.



export.txt (1 KB)

Hi Ian. You are correct - the #{Site} format doesn’t work for step template parameters. It does work for project variables, but for consistency you can use Octopus.tryFindVariable, Octopus.findVariable or Octopus.findVariableOrDefault.

I’ve included some examples below.

// It's a good idea to copy the value into a variable to avoid quoting issues

// tryFindVariable : name:string -> string option
let connectionString = Octopus.tryFindVariable "MyApp.ConnectionString"
match connectionString with
    | Some x -> printf "Connection string is: %s" x
    | None -> printf "Connection string not found"
// Or one of the simplified versions

// Throws KeyNotFoundException when variable does not exist
// findVariable : name:string -> string
let connectionString = Octopus.findVariable "MyApp.ConnectionString"

// Returns default value when variable does not exist
// findVariableOrDefault : defaultValue:string -> name:string -> string
let connectionString = Octopus.findVariableOrDefault "Default Value" "MyApp.ConnectionString"

Matt C