Using project variables in configuration transforms

Hi,

I am having trouble using project variables in configuration transforms. I have the following setup:

  • One environment “Demo”
  • Multiple targets within the environment : Demo1, Demo2, Demo3 etc.
  • There is a project variable “EnvironmentName” scoped to each target above.

Each target has its own app.config, connection.config etc., so there are app.Demo1.config, app.Demo2.config etc. I would like to transform these based on what target they are being deployed to.

I used the following “Additional transform”
*.#{EnvironmentName}.config => *.config

but it does not seem to be working. Is this configuration even supported?

Hi,

Thanks for reaching out! That configuration is supported, but It’ll all come down to what the values of your variables are at the moment of the deployment. We can give you a hand with this if you help us with this info:

  1. A screenshot of your variables screen where I can see all the values assigned to #{EnvironmentName}

  2. A screenshot of your package contents where I can see the names of all the .config files. You can use this tool for this: https://npe.codeplex.com/

  3. Finally, follow the below steps to provide afull deployment log

1) Add these 2 variables to your project http://docs.octopusdeploy.com/display/OD/Debug+problems+with+Octopus+variables

2) Create a new release (so the new variables take effect) and deploy it. If possible skip as many steps as you can and only leave step we are troubleshooting in order to avoid the noise in the log.

3) Send us the raw log of that deployment http://docs.octopusdeploy.com/display/OD/Get+the+raw+output+from+a+task

Best regards,
Dalmiro

Hi Dalmiro,

Thanks for taking your time to look into this. Please find below the requested info

Variables
[cid:image001.png@01D2351F.0D36D000]

Transformation config
[cid:image002.png@01D2351F.0D36D000]

Package content
[cid:image003.png@01D2351F.0D36D000]

Deployment log enclosed. Please disregard the error with PowerShell script which is unrelated.

Pawel

ServerTasks-6073.log.txt (81 KB)

HI,

Thanks for sending over all that info :slight_smile:

The transformations seem to be working.They go from lines 405 to 836 and on each transformation Octopus tells you which files were used. Can you double check that the correct file was used for the transformations on each time, and hopefully spot the ones you think are not working properly?

Thanks,
Dalmiro

The lines that show each transformation look like this

16:12:59   Info     |       Transforming 'C:\Octopus\Applications\ACA_DEMO1\DEMO\ACATS\2016.11.2.205-demo-1\ACATSDeploy\Valuation\log4net.config' using 'C:\Octopus\Applications\ACA_DEMO1\DEMO\ACATS\2016.11.2.205-demo-1\ACATSDeploy\Valuation\log4net.Demo1.config'.

Hi Dalmiro,

Thanks for the feedback. Let me double check on this and I will revert back to you.

Pawel

Hi Dalmiro,

Correct, from the log file it looks like transformation works but in fact it does not. Please see below a sample for connection string.

The file is empty
[cid:image001.png@01D23F65.A486F340]

Given the following source
[cid:image002.png@01D23F65.A486F340]

This is the relevant log
16:12:59 Info | Performing variable substitution on ‘C:\Octopus\Applications\ACA_DEMO1\DEMO\ACATS\2016.11.2.205-demo-1\Deploy.ps1’
16:12:59 Info | Transforming ‘C:\Octopus\Applications\ACA_DEMO1\DEMO\ACATS\2016.11.2.205-demo-1\ACATSDeploy\Analytics\connections.config’ using ‘C:\Octopus\Applications\ACA_DEMO1\DEMO\ACATS\2016.11.2.205-demo-1\ACATSDeploy\Analytics\connections.Demo1.config’.
16:12:59 Verbose | Executing Insert (transform line 7, 4)
16:12:59 Verbose | on /connectionStrings/add[@name=‘ACATSDEMO1’]
16:12:59 Verbose | Applying to ‘connectionStrings’ element (source line 2, 2)
16:12:59 Verbose | Inserted ‘add’ element
16:12:59 Verbose | Done executing Insert
16:12:59 Verbose | Executing Insert (transform line 10, 4)
16:12:59 Verbose | on /connectionStrings/add[@name=‘OESACATSDEMO1’]
16:12:59 Verbose | Applying to ‘connectionStrings’ element (source line 2, 2)
16:12:59 Verbose | Inserted ‘add’ element
16:12:59 Verbose | Done executing Insert
16:12:59 Verbose | Executing Insert (transform line 13, 4)
16:12:59 Verbose | on /connectionStrings/add[@name=‘ANLTACATSDEMO1’]
16:12:59 Verbose | Applying to ‘connectionStrings’ element (source line 2, 2)
16:12:59 Verbose | Inserted ‘add’ element
16:12:59 Verbose | Done executing Insert

From: Pawel Sokolowski
Sent: Thursday, November 03, 2016 4:16 PM
To: ‘Dalmiro Grañas’ tender2+d03c0c1805@tenderapp.com
Subject: RE: Using project variables in configuration transforms [Problems #48523]

Hi Dalmiro,

Thanks for the feedback. Let me double check on this and I will revert back to you.

Pawel

image001.png

Hi Pawel,

I’m gonna need to see the package’s contents to see what’s going on here. Can you please upload a copy of it to this private folder: https://file.ac/iE2tYXRnt3Q/

Feel free to remove any other file that’s not involved in the config transform process. Just make sure to leave the configs in the correct subfolders.

Thanks,
Dalmiro

Hi Dalmiro,

I just uploaded the entire package to the portal. Please keep in mind some of these configurations contain confidential information, so please be sure it’s handled privately and properly discarded after the investigation is closed.

The configurations in question is in this folder 2016.11.2.200-demo-1_5\ACATSDeploy\Analytics. Specifically the connection.config.

Let me know if you have any questions.

Pawel

Hi Pawel,

Deep apologies for the terrible delay here.

Is there any chance you can add the below code as a post deploy script on your package step and then follow the same instructions as in my first post to send a full log?

$file = ".\2016.11.2.200-demo-1_5\ACATSDeploy\Analytics\connections.config"

write-output "The content of $file post transforms is:"

get-content $file -verbose

make sure the path for $file is correct. I’m trying to aim to the transformed file

Thanks,
Dalmiro

Thank you for your email. I am currently out of the office, returning November 28, 2016. Should your request need immediate handling, please reach out to Johan Glozman (jglozman@acats.commailto:jglozman@acanpf.com).

Hi Dalmiro,

This is really strange but just adding the custom script section to the process fixed the issue. Even if I leave the sections blank, it still works. I will do a bit more testing here and revert back to you.

Thanks,

Pawel