Search code examples
octopus-deploy

Variable with multiple roles


I am having trouble getting the right variable based on a Role.

Perhaps I have the answer but I am not sure and could not find it in the documentation and here in the other questions.

TL;DR:

Multiple Roles on a variable use an OR, not an AND?

Intro

In Infrastructure I have multiple roles assigned to a machine:

  • WebServer
  • ApplicationServer
  • ApplA
  • ApplB

A variable has two values, each value has the role WebServer and ApplA or ApplB. enter image description here

In Process the same combination of the Roles WebServer and ApplA is used (or WebServer and ApplB). enter image description here

Problem

The value of the variable of ApplB is used in the step with ApplA.

It seems that this is because it uses an OR between the Roles and not a AND.

Correct?


Solution

  • That's right. If multiple roles are applied in the scope, it means that the variable will have that value for both of those roles individually, not together. You can combine scopes of different types (like DEV and ApplA) but not of the same time.

    This section from the docs has a little more information on scope precedence and what happens if there are conflicting values.

    In your deployment process, the "Deploy site" steps will run for all targets that have WebServer or ApplA. That might not be what you want.

    In this case, you can consider dropping the webserver role for the purposes of scoping the variables and the deployment steps or combine it with your other tags to make them a little more specific. Instead of WebServer, ApplA, and ApplB, you can replace those with ApplA-Web and ApplB-Web for use in your steps and variables.

    I hope that helps!