1

I am using Release Manager 2015 to deploy my application.

I am using Microsoft's Extension Utilities pack to do this:

Extension Utility Pack - Documentation

This simply states:

Tokenization based pattern replacement

This task finds the pattern __<pattern>__ and replaces the same with the value from the variable with name <pattern>.
Eg. If you have a variable defined as foo with value bar,
on running this task on a file that contains __foo__ will be changed to bar.

So in my web.config.token file I simply add:

<add name="ADConnectionString" connectionString="__ADConnectionString__" />

and in release manager under variables created a variable with the name ADConnectionString which is then picked up during the step and replaced.

My question is that I cannot figure out a way to replace a tokenized string within a string.

<add name="CreateTextWriter" initializeData="directory=D:\__WEBLOGDIR__\__ENVIRONMENT__; basename=Web" />

This will work however

<host name="cache1.__ENVIRONMENT__.__DOMAIN__" cachePort="1"/>

will not. This is due to the RegEx being used for the matching.

$regex = '__[A-Za-z0-9._-]*__'
$matches = select-string -Path $tempFile -Pattern $regex -AllMatches | % { $_.Matches } | % { $_.Value }

This will match the whole string rather than each tokenized string. To get around this I have changed the RegEx slightly to not be greedy in its selection.

$regex = '__[A-Za-z0-9._-]*?__'

Hope this helps someone else.

Chris
  • 805
  • 6
  • 19
  • I do not see the issue you describe, can you add an example? – Giulio Vian Jul 22 '16 at 09:23
  • Author of the Tokenizer task here. Can you please clarify what do you mean by '2 variables for each line' ? I can only see one variable per line in the example that you provided? – Harshil Lodhi Jul 24 '16 at 14:21
  • @HarshilLodhi I have ammended the question, as I have found another scenario that wasn't working for me. If this is something that you want adding to the GitHub forum let me know. – Chris Aug 08 '16 at 11:40
  • I've just had to this again on a new Build instance, the place to change the PowerShell script can be found here: C:\agent\tasks\Tokenizer\1.1.2 – Chris Nov 16 '16 at 16:35
  • I have the same problem as in the example "". The tokenizer will look for one variable "ENVIRONMENT__.__DOMAIN" instead of the two intended variables "ENVIRONMENT" and "DOMAIN". – Ingo Strauch Aug 29 '17 at 12:27
  • Hi Ingo, have you tried changing the regex in the powershell script as shown above? It is found on the build server, default location c:\Agent\tasks\Tokenizer\. If you add the ? this will allow both variables to be tokenized correctly – Chris Aug 30 '17 at 08:08

0 Answers0