Variable Scoping Precendence

Hi,

We are in the process of switching servers over from 2008 to 2012. As such and with our test team wanting to validate the differences between them, I have two different hostnames for the sites. However they are both in the same environment.

So for scoping the variable, I left the one that had previously been scoped to the environment as is. Example: Environment: Dev
For the new one, I scoped it as follows: Environment: Dev, Machines: MySecondDevServer

Now obviously since I’m being specific to a machine I wouldn’t need “dev” for environment on the this item, however at some point, I would prefer just to remove the machine specific item since that is likely to be the one I keep and it seems to help somewhat in sorting and it doesn’t seem as though it should hurt anything other than being redundant.

However, what is ending up happening is that my config is picking up the Environment specific setting only. I’m wondering if it is an issue of precedence, and if
A) There is a listing of order of precedence in evaluating variables (Didn’t see anything specific on the documentation page although it seems to be hinted at)
B) There is a way to do what I’m trying to do without having to switch to listing by individual machines.

Hi Mike,

Thanks for getting in touch! Sorry about the delay in getting back to you.
My suggestion would be to create a second Dev environment (such as Dev2012) and as you switch each server move it into the new environment. With Lifecycles you can now deploy to both at once so it would assure that the variables are being correctly evaluated. It might also help to know at a glace what has been moved and what hasn’t.

Seems slightly easier than scoping per machine. What do you think?
Vanessa

As for whether it’s easier, that’s only part of the question (additionally web transforms would have to change to reference the new environment).

If I have a whole dev environment and I have one machine I find that I need to change the variables on, does that mean I need to move that machine out of the dev environment OR individually include all machines (rather than specify “Dev” for an environment and then for the variable I want different, also specify machine?)

Example: Machines 1-5
Environment: Dev
Binding: mycodedev.mydomain.com

Environment: Dev
Machine: MyPOCBox
Binding: mycode.dev.mydomain.com

In that example from what I’ve seen “Dev” seems to be what evaluates last which seems faulty, both based on what I would expect and what the documentation seems to suggest. I’m not sure how “Role” and “Step” fit into the pyramid of precedence (more or less specific), but a machine would definitely seem more specific than an enviroment.

Past that even if I then do this, it doesn’t make anything better because it will still fall into dev above:

Environment:
Machine: MyPOCBox
DirectoryToInstall: C:\inetpub\mycode\subcode

Hi Mike,

Yeah, you are totally right about the environment for configs.
So how about a role instead? if say those machines have a web-server role you could make a new web-server2012 role for the new machines. Then you just need to add the role to the corresponding steps and make 1 new variable without continually scoping a new machine.

This is the precedence (from our documentation):

Since variables can be scoped in many different ways, there needs to be a predictable, deterministic order in which they are resolved. The list below is the priority in which variable scopes take precedence - the top items are considered higher priority than the bottom ones:
The current step/action (most specific)
The current machine
Roles applied to the current machine and targeted by the current step
Roles applied to the current machine
The target environment
No scope (least specific)

So I will test the scenario you described because the machine should have overwritten that variable.

Vanessa

OK, I can definitely confirm that this was happening. I’m going to have to try to reproduce because I needed to fix it when it happened. And to be honest I’m not sure the best way to pass this information on to you.

The scenario I had was similar to this:
variable1, value: 1st value, scope: environment: Dev, QA, Performanance
variable2, value: 2nd value, scope: environment: Dev, QA, machines: 2012DevServer, 2012QAServer

I’m wondering if it’s a case where adding the environment in the second case messes things up. Because technically what I’m trying to do is override it for that specific machine, not all of Dev or QA (but I initially added those because that is where those boxes are and it seemed to make sense to scope them), and because Octopus sees Dev/QA again listed it says “Hey we’ve already got one of these” and dumps the second occurrence.

-Mike

Hi Mike,

I’ll try my hardest to replicate this and see what I can find. What specific version are you running?

Vanessa

I created a test project, created a “ThisIsATest” variable and web.config app setting. Set it to “DefaultValue” in the web.config. In the variables section, I made 2 line entries for “ThisIsATest”, set one to “Value1” and the other to “Value2”. Uploaded a package with just the web.config and then tried switching the scopes as such.

ThisIsATest – Value1 – Machine: Server1, Environment: Dev
ThisIsATest – Value2 – Machine: Server2, Environment: Dev

On machine 1, the value was transformed to Value1 and on machine 2, the value was transformed to Value2.*

ThisIsATest – Value1 – Machine: Server1, Environment: Dev
ThisIsATest – Value2 – Environment: Dev

On machine 1, the value was transformed to Value1 and on machine 2, the value was transformed to Value2.*

ThisIsATest – Value1 – Environment: Dev
ThisIsATest – Value2 – Machine: Server2, Environment: Dev

On machine 1, the value was transformed to Value1 and on machine 2, the value was transformed to Value2.*

ThisIsATest – Value1 – Machine: Server2, Environment: Dev
ThisIsATest – Value2 – Environment: Dev

On machine 1, the value was transformed to Value2 and on machine 2, the value was transformed to Value1.*

ThisIsATest – Value1 – Environment: Dev
ThisIsATest – Value2 – Machine: Server1, Environment: Dev

On machine 1, the value was transformed to Value2 and on machine 2, the value was transformed to Value1.*

So the theory below doesn’t seem to be right and none of the iterations seem to cause issues. I’ll have to figure out what was different from what I initially had on the actual project.

    • This is checking both the output from Octo and the actual values on the server

Realized I forgot to include version 2.6.2.845


I created a test project, created a “ThisIsATest” variable and web.config app setting. Set it to “DefaultValue” in the web.config. In the variables section, I made 2 line entries for “ThisIsATest”, set one to “Value1” and the other to “Value2”. Uploaded a package with just the web.config and then tried switching the scopes as such.

ThisIsATest – Value1 – Machine: Server1, Environment: Dev
ThisIsATest – Value2 – Machine: Server2, Environment: Dev

On machine 1, the value was transformed to Value1 and on machine 2, the value was transformed to Value2.*

ThisIsATest – Value1 – Machine: Server1, Environment: Dev
ThisIsATest – Value2 – Environment: Dev

On machine 1, the value was transformed to Value1 and on machine 2, the value was transformed to Value2.*

ThisIsATest – Value1 – Environment: Dev
ThisIsATest – Value2 – Machine: Server2, Environment: Dev

On machine 1, the value was transformed to Value1 and on machine 2, the value was transformed to Value2.*

ThisIsATest – Value1 – Machine: Server2, Environment: Dev
ThisIsATest – Value2 – Environment: Dev

On machine 1, the value was transformed to Value2 and on machine 2, the value was transformed to Value1.*

ThisIsATest – Value1 – Environment: Dev
ThisIsATest – Value2 – Machine: Server1, Environment: Dev

On machine 1, the value was transformed to Value2 and on machine 2, the value was transformed to Value1.*

So the theory below doesn’t seem to be right and none of the iterations seem to cause issues. I’ll have to figure out what was different from what I initially had on the actual project.

    • This is checking both the output from Octo and the actual values on the server

Hi Mike,

So does this mean you can’t replicated it outside of the project? That is interesting. Have you tried turning on the variable logging during a deployment to try to figure out what could be overwriting the variable?
http://docs.octopusdeploy.com/display/OD/Debug+problems+with+Octopus+variables I’d be happy to look over the results if you want to provide a deployment log: http://docs.octopusdeploy.com/display/OD/Get+the+raw+output+from+a+task

Vanessa

I’m not sure if it is the project or not that is the issue. But I haven’t been able to duplicate elsewhere. And every where I find it are the times I need to fix it immediately because people are screaming. If I catch it again, I will follow the steps above and see what I can do.

I will have to figure out how to time this so I can turn on debugging.
I’m including more detail on actual names here because what I’m seeing doesn’t make much sense.

Server referenced
GGWQAAPPS1—>I was going for the value in the substitution should to be c:\traceNew, but it shows up as c:\tracePP
[cid:88A125D7-383F-4973-808B-267CCF234844]

From the variables page:
[cid:1E2BFA68-D61A-4341-90BA-0ABE1E3DB39A]

From the “raw” web.config:
[cid:C6BE4B95-2FCD-425C-B727-025FBBF0D0B3]

LogLocation doesn’t show up here at all in the deployment.

Success: Deploy Boost.HealthPortal.Web on ggwqaapps1
09:26:42 Info | Beginning deployment…
09:26:43 Verbose | Begin deployment of package: Boost.HealthPortal.Web.1.4.5.102-Dev
| Package file path: C:\Octopus\Applications.Tentacle\Packages\Boost.HealthPortal.Web.1.4.5.102-Dev_729A0944E54F09488466288FE3EB6E7C.nupkg
| Package file hash: 70ffc72398fcd3acf2f6fe56b2c0c3d8b1f7df60
| Tentacle Agent information:
| - Machine name: GGWQAAPPS1
| - Is 64-bit: True
| - Service user name: OctoTentQAApp
| - CLR version: 4.0.30319.18063
| - Current directory: C:\Windows\system32
| - OS version: Microsoft Windows NT 6.1.7601 Service Pack 1
| - Tentacle version: 2.6.2.845
09:26:43 Verbose | Package will be extracted to: C:\Octopus\Applications\QA
09:26:43 Verbose | Installing package Boost.HealthPortal.Web.1.4.5.102-Dev from uploaded package cache into C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev
09:26:47 Verbose | 843 files were extracted from the package
09:26:47 Verbose | Initial variable evaluation performed.
09:26:47 Verbose | Variables have been fully evaluated.
09:26:47 Verbose | Running procedure ‘Delete temporary package files’
09:26:47 Verbose | Looking for target files for variable substitution…
09:26:47 Verbose | Looking for any configuration transformation files
09:26:47 Verbose | Looking for appSettings and connectionStrings in any .config files
09:26:48 Verbose | The package has been installed to: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev
09:26:48 Verbose | If you would like the package to be installed to an alternative location, please specify the variable ‘Octopus.Action.Package.CustomInstallationDirectory’
09:26:49 Verbose | Storing a record of the deployment.
09:26:49 Info | Deployment complete.
|
| Success: Substitute variables in Web.config
09:26:47 Info | Loading file ‘C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\Web.config’ for Octopus variable substitution
09:26:47 Verbose | Binding variables…
09:26:47 Verbose | Evaluating template…
09:26:47 Verbose | Truncating original file and inserting new contents; utf-8 encoding will be used…
09:26:47 Info | Substitution complete.
|
| Success: Find and update variables in azure.dev.config
09:26:47 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\azure.dev.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: Find and update variables in Web.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\Web.config
09:26:48 Info | Updating appSettings and connectionStrings in: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\Web.config
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘DebugOutputFolder’] to ‘C:\BodyGuardianPP\Logs’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘BulkDirectory’] to ‘C:\bulkPP’
09:26:48 Info | Setting //[local-name()=‘connectionStrings’]/[local-name()=‘add’][@name=‘ASPNETMembershipConnectionString’] to ‘Data Source=sqlqaclus1\qa;Initial Catalog=ASPNET;Integrated Security=True;’
09:26:48 Info | Setting //[local-name()=‘connectionStrings’]/[local-name()=‘add’][@name=‘AccountManagementConnectionString’] to ‘Data Source=sqlqaclus1\qa;Initial Catalog=AccountManagementNew;Integrated Security=True;’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘CustomBGSettingsDirectory’] to ‘\mediaprodclus1\media\BodyGuardian\servicesqa.preventice.com
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘ErrorRecipients’] to ‘bgqaalerts@preventice.commailto:'bgqaalerts@preventice.com
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘GoogleAnalyticsAccountId’] to ‘UA-40925432-4’
09:26:48 Info | Setting //[local-name()=‘connectionStrings’]/[local-name()=‘add’][@name=‘MedicalExchangeConnectionString’] to ‘Data Source=sqlqaclus1\qa;Initial Catalog=MedicalExchangeNew;Integrated Security=True;’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘ReportsStorageLocation’] to ‘\mediaprodclus1\media\BGReporting\QA’
09:26:48 Info | Setting //[local-name()=‘connectionStrings’]/[local-name()=‘add’][@name=‘WebApplicationConnectionString’] to ‘Data Source=sqlqaclus1\qa;Initial Catalog=Web.Account;Integrated Security=True;’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘HelpSupportURL’] to ‘https://bgqa.preventice.com/help
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘AzureConfigFile’] to ‘C:\AzureConfigs\azure.config’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘ResourcesURL’] to ‘https://bgqa.preventice.com/themes/preventice/resources.xml
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘ReportServiceURL’] to ‘https://servicesqa.preventice.com/reporting/reports.svc
09:26:48 Info | Setting //[local-name()=‘connectionStrings’]/[local-name()=‘add’][@name=‘AccountManagementNewConnectionString’] to ‘Data Source=sqlqaclus1\qa;Initial Catalog=AccountManagementNew;Integrated Security=True;’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘AuthorizedBodyguardianDeviceImporters’] to ‘ebsuperuser,josuperuser,jrotter,gmsuperuser’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘WithingsDebugOutputFolder’] to ‘C:\Withings\Logs’
09:26:48 Info | Setting //[local-name()=‘appSettings’]/[local-name()=‘add’][@key=‘ExportFolder’] to ‘C:\bulkPP\bgexports’
|
| Success: Find and update variables in azure.dev.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\bin\azure.dev.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: Find and update variables in Web.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\modules\administration\Web.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: Find and update variables in Web.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\modules\patient\Web.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: Find and update variables in Web.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\modules\patient\ecg\Web.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: Find and update variables in Web.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\modules\system\Web.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: Find and update variables in Web.config
09:26:48 Verbose | Scanning configuration file: C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev\modules\user\Web.config
09:26:48 Info | No matching setting or connection string names were found.
|
| Success: IIS site BG
09:26:48 Info | Updating IIS website named ‘BG’
09:26:49 Info | The IIS website named ‘BG’ has had its path updated to: ‘C:\Octopus\Applications\QA\Boost.HealthPortal.Web\1.4.5.102-Dev’

Yet it ends up as C:\tracePP in the web.config.


Michael Peterson
IT Deployment Specialist
Office 507.218.3053
Skype preventiceMAP
e-mail mpeterson@preventice.commailto:mpeterson@preventice.com

Screen_Shot_2015-03-16_at_11.04.18_AM.png