Specify deployment target by variable?

Is there a way to define a variable in one step that specifies which deployment target a subsequent step runs on? My use case is a job that copies database backups from whichever database server holds the database for a given tenant. Right now we have the copy job scoped by a tenant tag which matches the server that the database is on for that tenant. If that database gets moved and no one changes the tenant tag, the job won’t work as it’s running on the wrong server. I’d like to automate this so we don’t have to worry about it anymore.

I can identify the database server in a script but don’t know how to pass that to the step that grabs the backup so it only runs on that one deployment target. The only workaround I can think of is to define a variable with the server name and have the copy step run on all servers but not do anything if the hostname doesn’t match.

Another possibility is to have the copy run from the desired destination, but they have multiple options for that and some aren’t Octopus targets.

Hi Tim,

Yes, that can be a bit of a pickle. I ran into something similar when I was working with VMSS. Octopus wanted to deploy to all the machines in the VMSS, but I only wanted to deploy to a subset of machines (the newly added ones).

I wrote how I accomplished that here:

The TL;DR; of that is to try setting the run condition to be:

#{unless Octopus.Deployment.Error}
        #{Octopus.Action[YOUR STEP NAME].Output.YOUR_OUTPUT_VAR | Contains #{Octopus.Machine.Name} }
#{/unless}

This does assume your server name is equal to your machine name. If that is not the case, there will be some additional work in your earlier step to pull back the machine name or ID, in which case, let me know and I can see if I can rustle up a sample script.

Please note: you’ll need to be running Octopus 2021.2+ for this to work.

That looks great. Unfortunately we aren’t up to date on the version for the instance I’m working with, though I hope to be soon. I’ll definitely keep that list of new run conditions in my back pocket.

On an older version, you could try, though your mileage my vary

#{unless Octopus.Deployment.Error}
        #{Octopus.Action[YOUR STEP NAME].Output.YOUR_OUTPUT_VAR == #{Octopus.Machine.Name} }
#{/unless}