Dynamic Step Output Variable

I want to read from an octopus step but is it possible to make it dynamic? For example, I have a step that grabs the app insights key entitled Get AppInsights InstrumentationKey for WebApi. I then read this into a variable using the following #{Octopus.Action[Get AppInsights InstrumentationKey for WebApi].Output.InstrumentationKey}.

I want to have two steps called:

  • Get AppInsights InstrumentationKey for WebApi EUN
  • Get AppInsights InstrumentationKey for WebApi EUW

However, is it possible to then have the Octopus Action to read from the correlating step? For example, something like

#{Octopus.Action[Get AppInsights InstrumentationKey for WebApi #{Region}].Output.InstrumentationKey}

Not sure what the syntax would be.

Thanks, RR.

Hello @ringrippa,

That syntax does work! I ran a couple of tests using the following basic scripts:

Project Variable Region set to Alpha/Beta in different environments.

  • Step 1 Set Ouput Alpha:
    • Set-OctopusVariable -Name "Key" -Value "Alpha"
  • Step 2 Set Ouput Beta:
    • Set-OctopusVariable -Name "Key" -Value "Beta"
  • Step 3 Get Output :
    • Write-Host $OctopusParameters["Octopus.Action[Set Output #{Region}].Output.Key"]

The above test also worked replacing the step reference with a PowerShell variable like so:

$stepName = "Set Output Beta"
Write-Host $OctopusParameters["Octopus.Action[$stepName].Output.Key"]

Hopefully that helps get where you need to be - if you have any other questions, don’t hesitate to reach out!