Is it possible to script adding a deployment target into a variable scope?

Hi everyone!

I’ve got a question here, that is buzzing me in the past few days… On a deployment pipeline that we have, we have this variable, that is nothing more than the hostname(localhost to be more precise) to replace in one of the steps.

That variable has set as scopes and environment and a deployment target.

I am implementing a CI/CD, where I deploy several VM’s, and register the VM’s on Octopus Deploy(this part is implemented). But now I need to make sure that the variable scope is updated, in order to have the deployment targets there in its scope.

Is it something that can be scripted?

Or, was just thinking… Maybe if in the variable scope I only have the Environment, and remove the deployment target from there, it will work that way?


Hi @nunopedrosilva,

Thanks for getting in touch!

We do have a sample script for adding or editing a variable with scoping, it isn’t the simplest operation though, so, the script is quite bulky.

Changing the variable scoping to Environment would likely be a better option though, assuming that you want this variable value to apply to every single target within the deployment.

If your deployment is a little more complex and this variable should only be applied to some of the targets, then using the Target Role scoping may work well. It would allow you to apply the value to a subset of targets within the Environment based on the role(s) those targets have.