Anyway to reference an output variable without knowing what steps its from

Hi, I have a script that is outputting a few variables. I was wondering if there was someway to reference those variables when doing file variable substitution without having to use the full step path. So instead of Octopus.Action[StepA].Output.SomeVar just SomeVar.

The main reason is I dont want to have to change a bunch of existing references in files, but its also an implementation detail i’d prefer to leave out of my source code.



Thanks for getting in touch! I’m sorry to say that this is not possible, as Octopus creates multiple duplicate variables in each different step, due to this the step name is a part of the variable name. This includes any output variables you create. If you tried calling an output variable without the step name, Octopus would not know which variable you are referring to.

Let me know if you have any further questions.

Best regards,

Cool i got around it with a pre-deployment script that read the variables output from the step and did the substitution on the files manually.

Write-Host "Pre Deployment Script"

$extractPath = $OctopusParameters['Octopus.Action.Output.Package.InstallationDirectoryPath'] 
$prefix = "Octopus.Action[Set Custom Variables].Output.admin."
$configHash = @{}

$OctopusParameters.GetEnumerator() | Sort-Object Key | ForEach {
    $index = $_.Key.IndexOf($prefix)
    if ($index -gt -1) {
        $key = $_.Key.Substring($prefix.length)
        Write-host "$key => $($_.Value)"
        $configHash[$key] = $_.Value

$jsFiles = Get-ChildItem . *.js -rec
foreach ($file in $jsFiles)
    foreach ($key in $configHash.Keys) {
        $value = $configHash.Item($key)
        $content = Get-Content ($file.PSPath)
        $content = $content.Replace("#{$($key)}", $value)
        Set-Content -Path $file.PSPath -Value $content


Great! Thank you for sharing your work around here! Hopefully this can help someone in the future who may be stuck with the same issue. :slight_smile:

Please feel free to get in touch if you have any further questions

Best regards,