Code Monkey home page Code Monkey logo

vsts-replacetokens-task's Introduction

[ARCHIVED] Replace Tokens task

donate

This GitHub project has been archived. Ongoing development on this project can be found in https://github.com/qetza/replacetokens-task.

Azure Pipelines extension that replace tokens in text files with variable values.

Usage

If you are using the UI, add a new task, select Replace Tokens from the Utility category and configure it as needed:

Replace Tokens parameters

If your are using a YAML file, add a task with the following syntax:

- task: qetza.replacetokens.replacetokens-task.replacetokens@3
  displayName: 'Replace tokens'
  inputs:
    targetFiles: |
      **/*.config
      **/*.json => outputs/*.json

Note: the task will only work on text files, if you need to replace token in archive file you will need to first extract the files and after archive them back.

Parameters

The parameters of the task are described bellow, in parenthesis is the YAML name:

  • Root directory (rootDirectory): the base directory for searching files. If not specified the default working directory will be used. Default is empty string
  • Target files (targetFiles): the absolute or relative newline-separated or comma-separated paths to the files to replace tokens. Wildcards can be used (eg: **\*.config for all .config files in all sub folders). Default is **/*.config

Syntax: {file path}[ => {output path}]

  • web.config will replace tokens in web.config and update the file.
  • web.tokenized.config => web.config will replace tokens in web.tokenized.config and save the result in web.config.
  • config\web.tokenized.config => c:\config\web.config will replace tokens in config\web.tokenized.config and save the result in c:\config\web.config.

Wildcard support

  • *.tokenized.config => *.config will replace tokens in all {filename}.tokenized.config target files and save the result in {filename}.config.
  • **\*.tokenized.config => c:\tmp\*.config will replace tokens in all {filename}.tokenized.config target files and save the result in c:\tmp\{filename}.config.

Only the wildcard * in the target file name will be used for replacement in the output.
Relative paths in the output pattern are relative to the target file path.\

Negative pattern
If you want to use negative pattern in target file, use a semi-colon ; to separate the including pattern and the negative patterns. When using output syntax, only the wildcard in the first pattern will be used for generating the output path.

  • **\*.tokenized.config;!**\dev\*.config => c:\tmp\*.config will replace tokens in all {filename}.tokenized.config target files except those under a dev directory and save the result in c:\tmp\{filename}.config.
  • Files encoding (encoding): the files encoding used for reading and writing. The 'auto' value will determine the encoding based on the Byte Order Mark (BOM) if present; otherwise it will use ascii. (allowed values: auto, ascii, utf-7, utf-8, utf-16le, utf-16be, win1252 and iso88591). Default is auto
  • Write unicode BOM (writeBOM): if checked writes an unicode Byte Order Mark (BOM). Default is true
  • Escape type (escapeType): specify how to escape variable values. Value auto uses the file extension (.json and .xml) to determine the escaping and none as fallback. Default is auto (allowed values: auto, none, json, xml and custom)
  • Escape character (escapeChar): when using custom escape type, the escape character to use when escaping characters in the variable values.
  • Characters to escape (charsToEscape): when using custom escape type, characters in variable values to escape before replacing tokens.
  • Verbosity (verbosity): specify the level of log verbosity. Default is normal (note: error and system debug are always on) (allowed values: normal, detailed and off)
  • Action on missing variable (actionOnMissing): specify the action to take on a missing variable. Default is warn
    • silently continue (continue): the task will continue without displaying any message.
    • log warning (warn): the task will continue but log a warning with the missing variable name.
    • fail (fail): the task will fail and log the missing variable name.
  • Keep token for missing variable (keepToken): if checked tokens with missing variables will not be replaced by empty string. Default is false
  • Action on no file processed (actionOnNoFiles): specify the action when no file was processed. Default is continue (allowed values: continue, warn, fail)
  • Token pattern (tokenPattern): specify the pattern of the tokens to search in the target files. Default is default (allowed values: default, rm, octopus, azpipelines, doublebraces and custom)
  • Token prefix (tokenPrefix): when using custom token pattern, the prefix of the tokens to search in the target files. Default is #{
  • Token suffix (tokenSuffix): when using custom token pattern, the suffix of the tokens to search in the target files. Default is }#
  • Use legacy pattern (useLegacyPattern): if checked whitespaces between the token prefix/suffix and the variable name are not ignored. Default is false
  • Use legacy empty/default feature (useLegacyEmptyFeature): if check use the old empty & default values features. The new feature/code can now distinguish between an undefined variable and an defined empty variable without the use of a specific "empty" token (Empty value parameter). Default is true
  • Empty value (emptyValue): with legacy empty/default feature: the variable value that will be replaced with an empty string. Default is (empty)
  • Use default value (useDefaultValue): with new empty/default feature: if check replace variable not found with a default value specified in Default value. Default is false
  • Default value (defaultValue): the value to be used if a variable is not found. With legacy empty/default feature: do not set to disable default value feature with the legacy feature; to replace with an empty string set the default value to the Empty value. Default is an empty string
  • Enable transformations (enableTransforms): if checked transformations can be applied on variable values. Default is false. The following transformations are available:
    • lower: make variable value lower case. Example: #{lower(MyVar)}#
    • upper: make variable value upper case. Example: #{upper(MyVar)}#
    • noescape: disable variable value escaping. (this can be used if you want to inject raw JSON or XML for example). Example: #{noescape(MyVar)}#
    • base64: encode variable value in BASE64. Example #{base64(MyVar)}#
    • indent: indent newlines with support of 2 parameters; the first parameter after the variable name is the indent size (default 2) and the second is a boolean specifying if the first line must be indented also (default false). Examples #{indent(MyVar)}#, #{indent(MyVar, 4, true)}#
  • Transform prefix (transformPrefix): The prefix between transform name and token name. Default is (.
  • Transform suffix (transformSuffix): The suffix after the token name. Default is ).
  • Variable files (JSON or YAML) (variableFiles): the absolute or relative comma or newline-separated paths to the files containing additional variables. Wildcards can be used (eg: vars\**\*.json for all .json files in all sub folders of vars). YAML files must have the .ymlor .yaml extension otherwise the file is treated as JSON. Variables declared in files overrides variables defined in the pipeline.
  • Inline variables (YAML syntax) (inlineVariables): A YAML formatted string containing inline variables. Variables declared inline overrides variables defined in the pipeline and in files.
  • Variable separator (variableSeparator): the separtor to use in variable names for nested objects and arrays in inline variables or variable files. Default is .. Example: { 'My': { 'Value': ['Hello World!'] } } will create a variable My.Value.0 with the value Hello World!.
  • Enable recursion in values (enableRecursion): if checked token replacement (with transformation) will be run on values.Example: "Say: #{value1}#" with value1 = "hello #{upper(value2)}#" and value2 = "world!" will result in "hello WORLD!". Default is false
  • Send anonymous usage telemetry (enableTelemetry): if checked anonymous usage data (hashed collection and pipeline id, no file parameter values, no variable values) will be sent to the task author only to analyze task usage. Default is true

Output variables

The task creates the following as output variables:

  • tokenReplacedCount: the total number of tokens which were replaced by a variable.
  • tokenFoundCount: the total number of of tokens which were found.
  • fileProcessedCount: the total number of files which were processed.
  • transformExecutedCount: the total number of transformations which were executed.
  • defaultValueCount: the total number of default value used.

Data/Telemetry

The Replace Tokens task for Azure Pipelines collects anonymous usage data and sends them to its author to help improve the product by default. If you don’t wish to send usage data, you can change your telemetry settings through Send anonymous usage telemetry parameter or by setting a variable or environment variable REPLACETOKENS_DISABLE_TELEMETRY to true.

Tips

If you want to use tokens in XML based configuration files to be replaced during deployment and also have those files usable for local development you can combine the Replace Tokens task with the XDT tranform task:

  • create an XDT transformation file containing your tokens
  • setup your configuration file with local developement values
  • at deployment time
    • inject your tokens in the configuration file by using your transformation file
    • replace tokens in your updated configuration file

Release notes

New in 4.6.0

  • Task 5.3.0
    • Add support for indent transformation with indent size and indent first line parameters (326).
  • Task 4.4.0
    • Add support for indent transformation with indent size and indent first line parameters (326).
  • Task 3.12.0
    • Add support for indent transformation with indent size and indent first line parameters (326).

New in 4.5.0

  • Task 5.2.0
    • Fix recursion cycle detection (#308) (contributed by Chad Smith).
    • Add support for YAML multiple document files in variable files and inline variables (#287).
    • Add support for JSON with comments variable files (#299).
    • Add support for Node16 execution handler.
  • Task 4.3.0
    • Fix recursion cycle detection (#308) (contributed by Chad Smith).
    • Add support for YAML multiple document files in variable files and inline variables (#287).
    • Add support for JSON with comments variable files (#299).
  • Task 3.11.0
    • Fix recursion cycle detection (#308) (contributed by Chad Smith).
    • Add support for YAML multiple document files in variable files and inline variables (#287).
    • Add support for JSON with comments variable files (#299).

New in 4.4.1

  • Task 4.2.1
    • Fix compatibility with node 5.10.1 (#277).
  • Task 3.10.1
    • Fix compatibility with node 5.10.1 (#277).

New in 4.4.0

  • Task 5.1.0
    • Add support for inline variables (#252).
    • Add support for recursive token replacement in values (#201).
    • Add optional reworked feature to simplify empty and default values (this is a breaking change if enabled as the old Empty value is not used anymore but replaced by an empty variable declaration).
  • Task 4.2.0
    • Add support for inline variables (#252).
    • Add support for recursive token replacement in values (#201).
    • Add optional reworked feature to simplify empty and default values (this is a breaking change if enabled as the old Empty value is not used anymore but replaced by an empty variable declaration).
  • Task 3.10.0
    • Add support for inline variables (#252).
    • Add support for recursive token replacement in values (#201).
    • Add optional reworked feature to simplify empty and default values (this is a breaking change if enabled as the old Empty value is not used anymore but replaced by an empty variable declaration).

New in 4.3.0

  • Add task 5.0.0
    • Breaking change: Migrate task to Node10 execution handler needing agent 2.144.0 minimum (#228, #230).

New in 4.2.1

  • Task 4.1.1
    • Revert migrate tasks to Node10 execution handler (#233).
  • Task 3.9.1
    • Revert migrate tasks to Node10 execution handler (#233).

New in 4.2.0

  • Task 4.1.0
    • Migrate tasks to Node10 execution handler (#228, #230).
  • Task 3.9.0
    • Migrate tasks to Node10 execution handler (#228, #230).

New in 4.1.0

  • Task 4.0.1
    • Promoted to release.
    • Add base64 transform (#163).
    • Add action on no file processed (#210).
  • Task 3.8.0
    • Add base64 transform (#163).
    • Add action on no file processed (#210).

New in 4.0.0

  • Add support for multiple task versions.
  • Add task 4.x (preview)
    • Breaking change: Add output variables (#160). (some older version of TFS/Azure Pipelines doesn't support output variables when used in release pipelines)
    • Breaking change: Add dropdown parameter Token pattern to select token pattern (#131). (users with customized token pattern will need to manually select one or custom)

New in 3.7.1

  • Fix issue on binary files (#193).
  • Rollback output variables (#196).

New in 3.7.0

  • Add output variables tokenReplacedCount, tokenFoundCount and fileProcessedCount (#160).
  • Add support for variable transformations with Enable tranformations (#96).
  • Add default value for tokens not found with Default value (contribution from ClemensSutor).
  • Group log outputs in Azure Pipelines output.
  • Add support for variables in external YAML files with .yml or .yaml extension (#177).

New in 3.6.0

  • Add parameter Use legacy pattern with default value to false.

New in 3.5.2

  • Fix issue when token prefix present but not as a token prefix (#149).

New in 3.5.1

  • Fix issue when variable System.ServerType is not defined (#147).

New in 3.5.0

  • Add anonymous usage telemetry.
  • Ignore spaces between token prefix/suffix and variable name (#143).

New in 3.4.1

  • Fix JSON escaping of slash / (#138)

New in 3.4.0

  • Add summary in logs with number of tokens found and replaced (#126).
  • Add support for variables in external JSON files (#113).

New in 3.3.1

  • Breaking change: If you were using negative pattern you need to use the semi colon ; as a separator instead of new-line in Target files.
  • Fix negative pattern support (#127).

New in 3.3.0

  • Add support for custom output file and wildcard support (#114).

New in 3.2.2

  • Fix matching issue with directory (#122).

New in 3.2.1

  • Fix log issue with escaped secret values.

New in 3.2.0

  • Switch to jschardet for encoding detection when selecting auto in File encoding (#99).
  • Switch to azure-pipelines-task-lib v2.8.0.
  • Add auto to Escape type and set it as default value.
  • Move Escape type, Escape character and Characters to escape to the main paramters section for easier discoverability.

New in 3.1.0

  • Add Verbosity parameter to allow detail logs without using system.debug.

New in 3.0.0

  • Breaking change: If you were using the character escaping feature you need to select custom in Escape values type parameter.
  • Add support to escape JSON in variable values (contributed by Justin Gould)
  • Add support to escape XML in variable values (contributed by Justin Gould)
  • Add Windows 1252 and ISO 8859-1 encoding to File encoding (#67)

New in 2.3.0

  • Add support to escape characters in variable values (#52)

New in 2.2.1

  • Fix issue with backslash in default target files value on mac (#50)

New in 2.2.0

  • Fix issue on file not found when using network paths (#40, #41).

New in 2.1.0

  • Add support for comma-separator in Target files (#35).
  • Add Empty value parameter to allow token replacement with an empty string (#32).

New in 2.0.2

  • Fix invalid file permissions after saving files.

New in 2.0.0

  • Breaking change: Migrated code to typescript to support cross-platform agent. This change requires the use of an agent at least in version 2.105.0 which is not compatible with TFS 2015. If you need to install the task on TFS 2015, download the vsix from the repository: https://github.com/qetza/vsts-replacetokens-task/releases/download/v1.4.1/qetza.replacetokens-1.4.1.vsix
  • Breaking change: File encoding parameter is now used when reading and writing files. Previously it was only used when writing.
  • Breaking change: File encoding doesn't support 'utf-32' and 'utf-32 (big endian)' anymore.
  • Breaking change: Target files parameter now only uses the new line as a separator for multi-values (previously it used new-line and semi-colon).
  • Removed required Root directory, an empty value is equivalent to $(System.DefaultWorkingDirectory).

New in 1.4.1

  • Fix missing method issue with new xplat agent (2.104.1)

New in 1.4.0

  • Add variables expansion in variable values.
  • Escape token prefix and suffix in regex pattern.

New in 1.3.1

  • Fix wrong encoding constructors parameters.

New in 1.3.0

  • Replaced parameter Fail on missing with Action in Missing variables group.
  • Add Keep token parameter in 'Missing variables' group.
  • Fix issue on empty file.

New in 1.2.0

  • Add Root directory task parameter to configure file search root directory (contributed by Jesse Houwing).
  • Update Target files task parameter to support newline-separator (contributed by Jesse Houwing).

vsts-replacetokens-task's People

Contributors

chad-smith avatar clemenssutor avatar dependabot[bot] avatar gregwinterstein avatar iorlandoni avatar jessehouwing avatar qetza avatar skymogul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vsts-replacetokens-task's Issues

Add ability to provide default value in placeholder

Hello.

Awesome TFS extension!

One small issue that we faced with: we have lot's of environments (more than 100). And we have a rule to fail on missing variable.
So the problem is to add new variable. We frequently have a situation to add new variable like $(MyNewVariable) that is "True" for 99 envs, but "False" for only one.
But we also don't want to go to 99 envs and put "True" there. What we want is to have ability define default like that:
$(MyNewVariable|True)
$(MyOtherVariable|http://defaultsite.com)

So if there's no variable defined - the "True" will go by default (for second example it will be http://defaultsite.com).

The separator ("|" in my example) can be anything (so it can be "|" by default or user can pass it in TFS if he wants).

@qetza do you find any objections regarding adding that functionality?

Thanks

Webdeploy package integration

Guillaume,
Great idea, but I cannot make the task work with a webdeploy package that is deployed to Azure webapps.
any hints?

Thanks

PathTooLongException

I am deploying a website and have created a task entering a rootDirectory, targetFiles, encoding=auto, writeBOM = true, failonmissing=true token prefix/suffix __ to tokenise the webconfig files.
I run it on a windows server 2012 r2 standard version 6.2 build 9200 , with IIS version 8.5.9600.16384 and it works fine. When I try to run it on another windows server 2012 r2 standard version 6.2 build 9200 , with IIS version 8.5.9600.16384 it fails with "System.IO.PathTooLongException: The specified path, file name, or both are too long."
What else should I be comparing between the two servers to try and identify the issue?

Replace within scss file

Hello,

I need to replace path within an scss file. I tried several configurations. I'm missing something, but can't figure out what ! Thanks

In my file, I have : #{scssbgPath}#

Task config :

image

Below debug logs :
2017-07-30T06:37:02.6140594Z ##[debug]Evaluating condition for step: 'Replace tokens in \NatDec.Web\Content\scss\environnement.scss'
2017-07-30T06:37:02.6140594Z ##[debug]Evaluating: succeeded()
2017-07-30T06:37:02.6140594Z ##[debug]Evaluating succeeded:
2017-07-30T06:37:02.6140594Z ##[debug]=> (Boolean) True
2017-07-30T06:37:02.6140594Z ##[debug]Expanded: True
2017-07-30T06:37:02.6140594Z ##[debug]Result: True
2017-07-30T06:37:02.6140594Z ##[section]Starting: Replace tokens in \NatDec.Web\Content\scss\environnement.scss
2017-07-30T06:37:02.6150602Z ==============================================================================
2017-07-30T06:37:02.6150602Z Task : Replace Tokens
2017-07-30T06:37:02.6150602Z Description : Replace tokens in files
2017-07-30T06:37:02.6150602Z Version : 2.2.0
2017-07-30T06:37:02.6150602Z Author : Guillaume Rouchon
2017-07-30T06:37:02.6150602Z Help : More Information
2017-07-30T06:37:02.6150602Z ==============================================================================
2017-07-30T06:37:02.9251623Z ##[debug]agent.workFolder=d:\a
2017-07-30T06:37:02.9291649Z ##[debug]loading inputs and endpoints
2017-07-30T06:37:02.9301649Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2017-07-30T06:37:02.9321658Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2017-07-30T06:37:02.9321658Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2017-07-30T06:37:02.9331662Z ##[debug]loading INPUT_ACTIONONMISSING
2017-07-30T06:37:02.9331662Z ##[debug]loading INPUT_EMPTYVALUE
2017-07-30T06:37:02.9331662Z ##[debug]loading INPUT_ENCODING
2017-07-30T06:37:02.9341664Z ##[debug]loading INPUT_KEEPTOKEN
2017-07-30T06:37:02.9341664Z ##[debug]loading INPUT_ROOTDIRECTORY
2017-07-30T06:37:02.9341664Z ##[debug]loading INPUT_TARGETFILES
2017-07-30T06:37:02.9341664Z ##[debug]loading INPUT_TOKENPREFIX
2017-07-30T06:37:02.9341664Z ##[debug]loading INPUT_TOKENSUFFIX
2017-07-30T06:37:02.9351667Z ##[debug]loading INPUT_WRITEBOM
2017-07-30T06:37:02.9351667Z ##[debug]loading SECRET_FTPPASSWORD
2017-07-30T06:37:02.9361678Z ##[debug]loading SECRET_FTPUSER
2017-07-30T06:37:02.9361678Z ##[debug]loaded 14
2017-07-30T06:37:02.9481727Z ##[debug]rootDirectory=d:\a\3\a
2017-07-30T06:37:02.9481727Z ##[debug]check path : d:\a\3\a
2017-07-30T06:37:02.9481727Z ##[debug]encoding=utf-8
2017-07-30T06:37:02.9481727Z ##[debug]tokenPrefix=#{
2017-07-30T06:37:02.9491730Z ##[debug]tokenSuffix=}#
2017-07-30T06:37:02.9491730Z ##[debug]keepToken=false
2017-07-30T06:37:02.9491730Z ##[debug]actionOnMissing=warn
2017-07-30T06:37:02.9491730Z ##[debug]writeBOM=false
2017-07-30T06:37:02.9501728Z ##[debug]emptyValue=(empty)
2017-07-30T06:37:02.9501728Z ##[debug]targetFiles=\NatDec.Web\Content\scss\environnement.scss
2017-07-30T06:37:02.9501728Z ##[debug]pattern: #{((?:(?!}#).)*)}#
2017-07-30T06:37:02.9511738Z ##[debug]defaultRoot: 'd:\a\3\a'
2017-07-30T06:37:02.9521744Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2017-07-30T06:37:02.9521744Z ##[debug]findOptions.followSymbolicLinks: 'true'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.debug: 'false'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.nobrace: 'true'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.noglobstar: 'false'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.dot: 'true'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.noext: 'false'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.nocase: 'true'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.nonull: 'false'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.matchBase: 'false'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.nocomment: 'false'
2017-07-30T06:37:02.9531743Z ##[debug]matchOptions.nonegate: 'false'
2017-07-30T06:37:02.9541749Z ##[debug]matchOptions.flipNegate: 'false'
2017-07-30T06:37:02.9541749Z ##[debug]pattern: '
\NatDec.Web\Content\scss\environnement.scss'
2017-07-30T06:37:02.9601780Z ##[debug]findPath: 'd:\a\3\a'
2017-07-30T06:37:02.9601780Z ##[debug]statOnly: 'false'
2017-07-30T06:37:02.9611776Z ##[debug]findPath: 'd:\a\3\a'
2017-07-30T06:37:02.9611776Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2017-07-30T06:37:02.9611776Z ##[debug]findOptions.followSymbolicLinks: 'true'
2017-07-30T06:37:02.9611776Z ##[debug] d:\a\3\a (directory)
2017-07-30T06:37:02.9621785Z ##[debug]1 results
2017-07-30T06:37:02.9621785Z ##[debug]found 1 paths
2017-07-30T06:37:02.9621785Z ##[debug]applying include pattern
2017-07-30T06:37:02.9621785Z ##[debug]adjustedPattern: 'd:\a\3\a**\NatDec.Web\Content\scss\environnement.scss'
2017-07-30T06:37:02.9641887Z ##[debug]0 matches
2017-07-30T06:37:02.9651800Z ##[debug]0 final results
2017-07-30T06:37:02.9721808Z ##[section]Finishing: Replace tokens in **\NatDec.Web\Content\scss\environnement.scss

Fails on empty files

We have noticed that when attempting to replace tokens in empty files, the task fails with the following error:

[error]Cannot index into a null array

Would it be possible to skip empty files? I am told that we cannot delete these files as they are populated by the application at run time.

Secret variables can not be found

When trying to use the replace tokens task in our release, I found that variables that are marked as secret are can not be found.

I have a variable called 'ConnectionString' in our configuration set as secret, because it contains a password. The ReplaceTokens task generated the following warning:
##[warning]variable not found: ConnectionString

Can support for secret variables be added, or could you at least mention that they are not supported?

Regards,
David Perfors

Nothing happens on mac build agent

Hi,
I'm trying to build a xamarin forms ios app with a local mac as a build agent. Unfortunately when we run the replace tokens it doesn't seem to do anything but doesn't give an error either.

2017-08-31T03:36:28.3265210Z ##[section]Starting: Backend hostname
2017-08-31T03:36:28.3343470Z =============================================================================
2017-08-31T03:36:28.3360530Z Task         : Replace Tokens
2017-08-31T03:36:28.3376680Z Description  : Replace tokens in files
2017-08-31T03:36:28.3394230Z Version      : 2.2.0
2017-08-31T03:36:28.3410530Z Author       : Guillaume Rouchon
2017-08-31T03:36:28.3428910Z Help         : [More Information](https://github.com/qetza/vsts-replacetokens-task#readme)
2017-08-31T03:36:28.3447690Z ==============================================================================
2017-08-31T03:36:30.5793590Z ##[section]Finishing: Backend hostname

Any advice as to what might be happening?

Suggestion: escape file path JSON file

Hello,

I'm trying to use Replace Tokens to set a file path in a .json file.
My token is @@assets.root@@ and my variable has a normal file path. If this wasn't a .json file everything behaves as it should. However as you know in json the paths need to be escaped.

C:\my-path needs to be c:\\my-path.

Just hoping that this would make it in future versions (logic to escape paths when target is .json extension).

Can't downgrade to 1.4.1

I removed the newer version (I'm on TFS 2015) and tried to install 1.4.1. Getting the error:

A task definition with id 'a8515ec8-7254-4ffd-912c-86772e2b5962' has already been uploaded. To replace the existing definition, provide a task version which is greater than '2.0.1'.

image

image

Token replace?

Im missing something...
I see how to search for tokens, but where do i specific what gets replaced?
Token prefix and suffix to find tokens, but what gets replaced? Really strange.....

Nested variable replacement?

Are there any plans to support nested variable replacement so that __URL_TOKEN__ is replaced as http://dev/ when released to the Dev environment?

For example:

URL_TOKEN = $(URL_TOKEN_$(Release.EnvironmentName))
URL_TOKEN_Dev = http://dev/

The only way I imagine doing this currently is to simulate a dual-pass scenario by configuring two Replace Token tasks and changing the above to:

URL_TOKEN = __URL_TOKEN_$(Release.EnvironmentName)__
URL_TOKEN_Dev = http://dev/

Tokens not being replaced. Variables not found

I have a release definition that looks like this:

image

The 2nd replace task fails, while the 1st one succeeds. Here's an overview of my variables:

image

Here's the file that is being processed by the extension:

apiVersion: v1
kind: Secret
metadata:
  name: os-smog-api.secrets
  namespace: os-smog-api
data:
  measurementsDatabase: #{Secret.MeasurementsDb}#
  devicesDatabase: #{Secret.DevicesDb}#
  azureStorage: #{Secret.AzureStorage}#
  azureWebJobStorage: #{Secret.AzureWebJobStorage}#

Here's what happens in the release:

2017-11-28T23:26:14.1432824Z ##[debug]Evaluating condition for step: '[replace-tokens] os-smog-api/**/*.yaml'
2017-11-28T23:26:14.1432824Z ##[debug]Evaluating: succeeded()
2017-11-28T23:26:14.1432824Z ##[debug]Evaluating succeeded:
2017-11-28T23:26:14.1442495Z ##[debug]=> (Boolean) True
2017-11-28T23:26:14.1442495Z ##[debug]Expanded: True
2017-11-28T23:26:14.1442495Z ##[debug]Result: True
2017-11-28T23:26:14.1442495Z ##[section]Starting: [replace-tokens] os-smog-api/**/*.yaml
2017-11-28T23:26:14.1442495Z ==============================================================================
2017-11-28T23:26:14.1442495Z Task         : Replace Tokens
2017-11-28T23:26:14.1442495Z Description  : Replace tokens in files
2017-11-28T23:26:14.1442495Z Version      : 2.2.1
2017-11-28T23:26:14.1442495Z Author       : Guillaume Rouchon
2017-11-28T23:26:14.1442495Z Help         : v2.2.1 - [More Information](https://github.com/qetza/vsts-replacetokens-task#readme)
2017-11-28T23:26:14.1442495Z ==============================================================================
2017-11-28T23:26:14.3092867Z ##[debug]agent.TempDirectory=D:\Agents\OpenSmog01\w\_temp
2017-11-28T23:26:14.3152914Z ##[debug]loading inputs and endpoints
2017-11-28T23:26:14.3152914Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2017-11-28T23:26:14.3162534Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2017-11-28T23:26:14.3162534Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2017-11-28T23:26:14.3162534Z ##[debug]loading INPUT_ACTIONONMISSING
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_EMPTYVALUE
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_ENCODING
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_KEEPTOKEN
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_ROOTDIRECTORY
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_TARGETFILES
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_TOKENPREFIX
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_TOKENSUFFIX
2017-11-28T23:26:14.3172533Z ##[debug]loading INPUT_WRITEBOM
2017-11-28T23:26:14.3182536Z ##[debug]loading SECRET_AZURESTORAGE
2017-11-28T23:26:14.3182536Z ##[debug]loading SECRET_AZUREWEBJOBSTORAGE
2017-11-28T23:26:14.3182536Z ##[debug]loading SECRET_DEVICESDB
2017-11-28T23:26:14.3182536Z ##[debug]loading SECRET_MEASUREMENTSDB
2017-11-28T23:26:14.3182536Z ##[debug]loaded 16
2017-11-28T23:26:14.3202779Z ##[debug]Agent.ProxyUrl=undefined
2017-11-28T23:26:14.3202779Z ##[debug]Agent.CAInfo=undefined
2017-11-28T23:26:14.3202779Z ##[debug]Agent.ClientCert=undefined
2017-11-28T23:26:14.3252910Z ##[debug]rootDirectory=D:\Agents\OpenSmog01\w\r2\a\os-smog-api
2017-11-28T23:26:14.3262553Z ##[debug]check path : D:\Agents\OpenSmog01\w\r2\a\os-smog-api
2017-11-28T23:26:14.3262553Z ##[debug]encoding=auto
2017-11-28T23:26:14.3262553Z ##[debug]tokenPrefix=#{
2017-11-28T23:26:14.3262553Z ##[debug]tokenSuffix=}#
2017-11-28T23:26:14.3272537Z ##[debug]keepToken=false
2017-11-28T23:26:14.3272537Z ##[debug]actionOnMissing=fail
2017-11-28T23:26:14.3272537Z ##[debug]writeBOM=true
2017-11-28T23:26:14.3272537Z ##[debug]emptyValue=(empty)
2017-11-28T23:26:14.3272537Z ##[debug]targetFiles=**/*.yaml
2017-11-28T23:26:14.3272537Z ##[debug]pattern: #\{((?:(?!\}#).)*)\}#
2017-11-28T23:26:14.3283002Z ##[debug]defaultRoot: 'D:\Agents\OpenSmog01\w\r2\a\os-smog-api'
2017-11-28T23:26:14.3283002Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2017-11-28T23:26:14.3283002Z ##[debug]findOptions.followSymbolicLinks: 'true'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.debug: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.nobrace: 'true'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.noglobstar: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.dot: 'true'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.noext: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.nocase: 'true'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.nonull: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.matchBase: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.nocomment: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.nonegate: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]matchOptions.flipNegate: 'false'
2017-11-28T23:26:14.3283002Z ##[debug]pattern: '**/*.yaml'
2017-11-28T23:26:14.3312525Z ##[debug]findPath: 'D:\Agents\OpenSmog01\w\r2\a\os-smog-api'
2017-11-28T23:26:14.3312525Z ##[debug]statOnly: 'false'
2017-11-28T23:26:14.3312525Z ##[debug]findPath: 'D:\Agents\OpenSmog01\w\r2\a\os-smog-api'
2017-11-28T23:26:14.3312525Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2017-11-28T23:26:14.3312525Z ##[debug]findOptions.followSymbolicLinks: 'true'
2017-11-28T23:26:14.3322540Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api (directory)
2017-11-28T23:26:14.3322540Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts (directory)
2017-11-28T23:26:14.3332856Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps (directory)
2017-11-28T23:26:14.3332856Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api (directory)
2017-11-28T23:26:14.3342562Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\appsettings.Development.json (file)
2017-11-28T23:26:14.3342562Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\appsettings.json (file)
2017-11-28T23:26:14.3342562Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\appSettings.Production.json (file)
2017-11-28T23:26:14.3342562Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\appSettings.test.json (file)
2017-11-28T23:26:14.3342562Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Baseline.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\FastExpressionCompiler.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Marten.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\MediatR.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Microsoft.WindowsAzure.Storage.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Newtonsoft.Json.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Npgsql.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Core.Api.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Core.Queues.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Data.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Dto.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Events.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.deps.json (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.pdb (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.PrecompiledViews.dll (file)
2017-11-28T23:26:14.3352522Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.PrecompiledViews.pdb (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.runtimeconfig.json (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Api.xml (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Validation.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\OS.Smog.Validation.pdb (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Enrichers.Context.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Enrichers.Environment.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Enrichers.Thread.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Extensions.Logging.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Settings.Configuration.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Sinks.Console.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Sinks.Literate.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Sinks.Logentries.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Serilog.Sinks.PeriodicBatching.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Swashbuckle.Swagger.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Swashbuckle.SwaggerGen.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\Swashbuckle.SwaggerUi.dll (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\apps\OS.Smog.Api\web.config (file)
2017-11-28T23:26:14.3362517Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s (directory)
2017-11-28T23:26:14.3372920Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s\os-smog-api.deployment.yaml (file)
2017-11-28T23:26:14.3372920Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s\os-smog-api.secret.yaml (file)
2017-11-28T23:26:14.3372920Z ##[debug]  D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s\os-smog-api.service.yaml (file)
2017-11-28T23:26:14.3372920Z ##[debug]47 results
2017-11-28T23:26:14.3372920Z ##[debug]found 47 paths
2017-11-28T23:26:14.3372920Z ##[debug]applying include pattern
2017-11-28T23:26:14.3372920Z ##[debug]adjustedPattern: 'D:\Agents\OpenSmog01\w\r2\a\os-smog-api\**/*.yaml'
2017-11-28T23:26:14.3382863Z ##[debug]3 matches
2017-11-28T23:26:14.3392515Z ##[debug]3 final results
2017-11-28T23:26:14.3402878Z replacing tokens in: D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s\os-smog-api.deployment.yaml
2017-11-28T23:26:14.3412537Z ##[debug]BOM no found: default to ascii.
2017-11-28T23:26:14.3412537Z ##[debug]encoding: ascii
2017-11-28T23:26:14.3522876Z ##[debug]Release.ReleaseId=117
2017-11-28T23:26:14.3562537Z replacing tokens in: D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s\os-smog-api.secret.yaml
2017-11-28T23:26:14.3562537Z ##[debug]BOM no found: default to ascii.
2017-11-28T23:26:14.3562537Z ##[debug]encoding: ascii
2017-11-28T23:26:14.3562537Z ##[debug]Secret.MeasurementsDb=undefined
2017-11-28T23:26:14.3572520Z ##[debug]task result: Failed
2017-11-28T23:26:14.3622532Z ##[error]variable not found: Secret.MeasurementsDb
2017-11-28T23:26:14.3622532Z ##[debug]Processed: ##vso[task.issue type=error;]variable not found: Secret.MeasurementsDb
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.complete result=Failed;]variable not found: Secret.MeasurementsDb
2017-11-28T23:26:14.3632535Z ##[debug]Secret.DevicesDb=undefined
2017-11-28T23:26:14.3632535Z ##[debug]task result: Failed
2017-11-28T23:26:14.3632535Z ##[error]variable not found: Secret.DevicesDb
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.issue type=error;]variable not found: Secret.DevicesDb
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.complete result=Failed;]variable not found: Secret.DevicesDb
2017-11-28T23:26:14.3632535Z ##[debug]Secret.AzureStorage=undefined
2017-11-28T23:26:14.3632535Z ##[debug]task result: Failed
2017-11-28T23:26:14.3632535Z ##[error]variable not found: Secret.AzureStorage
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.issue type=error;]variable not found: Secret.AzureStorage
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.complete result=Failed;]variable not found: Secret.AzureStorage
2017-11-28T23:26:14.3632535Z ##[debug]Secret.AzureWebJobStorage=undefined
2017-11-28T23:26:14.3632535Z ##[debug]task result: Failed
2017-11-28T23:26:14.3632535Z ##[error]variable not found: Secret.AzureWebJobStorage
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.issue type=error;]variable not found: Secret.AzureWebJobStorage
2017-11-28T23:26:14.3632535Z ##[debug]Processed: ##vso[task.complete result=Failed;]variable not found: Secret.AzureWebJobStorage
2017-11-28T23:26:14.3642526Z replacing tokens in: D:\Agents\OpenSmog01\w\r2\a\os-smog-api\artifacts\k8s\os-smog-api.service.yaml
2017-11-28T23:26:14.3642526Z ##[debug]BOM no found: default to ascii.
2017-11-28T23:26:14.3642526Z ##[debug]encoding: ascii
2017-11-28T23:26:14.3672528Z ##[section]Finishing: [replace-tokens] os-smog-api/**/*.yaml

Can anyone explain why are the variables not being detected?

Request: Verbose logging

I would love to see an option to do "Verbose" logging, that is, log the line number, token name and replaced value when it's actually replaced, in addition to the log info of skipped variables.

Great plugin! I had a sketchy powershell script I was able to replace with this!

Release Fails with Empty Variable

Specifying an empty Release variable causes the release to fail with the error:

##[error]variable not found:

This is with the following task settings:

Missing variables > Action = fail
Advanced > Empty value = nothing/I removed the present value of (empty)

Remote token replacement

Hi,

Could you implement remoting for this task? That would make it easier when you're using 1 agent to deploy to multiple remote machines.

Keep up the good work!

Cannot find an overload for "UnicodeEncoding" and the argument count: "1" when processing .mof file

We're using DSC to generate .mof files. However, we get an error when tries to do a token replacement on it. Here's the output from part of the log. It process .config files fine

Agent:
NewAgent-Build
Start Time:
7/23/2016 6:08 AM
| Duration:
00:00:03
2016-07-23T05:08:01.3760081Z Executing the powershell script: C:\BuildAgent\tasks\replacetokens\1.3.0\replace-tokens.ps1

2016-07-23T05:08:02.5165502Z Replacing tokens in file 'C:\BuildAgent\_work\3122d4e92\New.App.CI\drop\__TargetMachine__.mof'...

2016-07-23T05:08:03.3604700Z ##[error]System.Management.Automation.MethodException: Cannot find an overload for "UnicodeEncoding" and the argument count: "1".

2016-07-23T05:08:03.3604700Z ##[error]   at System.Management.Automation.Adapter.GetBestMethodAndArguments(String methodName, MethodInformation[] methods, PSMethodInvocationConstraints invocationConstraints, Object[] arguments, Object[]& newArguments)

2016-07-23T05:08:03.3604700Z ##[error]   at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)

2016-07-23T05:08:03.3604700Z ##[error]   at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)

2016-07-23T05:08:03.3916599Z ##[error]Microsoft.PowerShell.Commands.WriteErrorException: Unknown encoding 'Unicode'.

Does it work for TFS on prem?

I downloaded and tried to install it in TFS 2015.2, but I am getting na error that this extension is not installed on any currently installed products.
Error log
7/20/2016 7:19:03 AM - Microsoft VSIX Installer
7/20/2016 7:19:03 AM - -------------------------------------------
7/20/2016 7:19:03 AM - Initializing Install...
7/20/2016 7:19:04 AM - Extension Details...
7/20/2016 7:19:04 AM - Identifier : replacetokens
7/20/2016 7:19:04 AM - Name : Replace Tokens
7/20/2016 7:19:04 AM - Author : qetza
7/20/2016 7:19:04 AM - Version : 1.3.0
7/20/2016 7:19:04 AM - Description : Task to replace tokens in files.
7/20/2016 7:19:04 AM - Locale : en-US
7/20/2016 7:19:04 AM - MoreInfoURL :
7/20/2016 7:19:04 AM - InstalledByMSI : False
7/20/2016 7:19:04 AM - SupportedFrameworkVersionRange : [0.0,2147483647.2147483647]
7/20/2016 7:19:04 AM -
7/20/2016 7:19:04 AM - SignatureState : Unsigned
7/20/2016 7:19:04 AM - Supported Products :
7/20/2016 7:19:04 AM - Microsoft.VisualStudio.Services
7/20/2016 7:19:04 AM - Version :
7/20/2016 7:19:04 AM -
7/20/2016 7:19:04 AM - References :
7/20/2016 7:19:04 AM - Signature Details...
7/20/2016 7:19:04 AM - Extension is not signed.
7/20/2016 7:19:04 AM -
7/20/2016 7:19:04 AM - Searching for applicable products...
7/20/2016 7:19:04 AM - Found installed product - Microsoft Visual Studio Enterprise 2015
7/20/2016 7:19:04 AM - Found installed product - Microsoft Visual Studio Professional 2015
7/20/2016 7:19:04 AM - Found installed product - Microsoft Visual Studio Community 2015
7/20/2016 7:19:04 AM - Found installed product - Microsoft Visual Studio 2015 Shell (Integrated)
7/20/2016 7:19:04 AM - Found installed product - Global Location
7/20/2016 7:19:04 AM - Found installed product - ssms
7/20/2016 7:19:04 AM - VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products.
at VSIXInstaller.App.InitializeInstall(Boolean isRepairSupported)
at VSIXInstaller.App.InitializeInstall()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

How to replace version?

Suppose I want to replace the version 5.2.0 to 5.2.1 without any variables declaration, replacing with just find and replace. How can I achieve this using this extension? I can not find useful information to do that. Please suggest.

Can we have a verbose mode to see which variables it has

I have a strange issue with one of my releases not having the tokens replaced - others work fine.

So it would be nice to have a verbose mode so I can see what tokens it thinks its found and what values it thinks its replacing

Getting System.Management.Automation.RuntimeException

Using current 1.4.0 version of extension and latest 2.104.1 agent version on Windows 10 with VSTS.

When the task is run it's failing with the following exception. It looks like it's thrown on each replacement. So we got 6 exceptions that are the same.

2016-08-03T17:27:14.5513455Z ##[error]System.Management.Automation.RuntimeException: Unable to find type [Microsoft.TeamFoundation.DistributedTask.Agent.Common.ContextExtensions].
2016-08-03T17:27:14.5513455Z    at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName)
2016-08-03T17:27:14.5513455Z    at System.Management.Automation.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
2016-08-03T17:27:14.5513455Z    at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Error Installing on TFS 2017 on-prem

Please assist, was trying to install package to on premises TFS running vs 2017 Enterprise, got the error below
Found installed product - Visual Studio Enterprise 2017
4/19/2018 12:18:39 PM - VSIXInstaller.NoApplicableSKUsException: This extension is not installable on any currently installed products.
at VSIXInstaller.App.GetInstallableData(String vsixPath, Boolean isRepairSupported, IEnumerable1& skuData) at VSIXInstaller.App.Initialize(Boolean isRepairSupported) at VSIXInstaller.App.Initialize() at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

please assist.

variable empty valu

Hello.
What do i have to do if the variable has to be replaced by an empty value?
I use VSTS and i don't see the tab meesing variable action on the task.

Regards,

Damien

Not replacing build numer

I am trying to replace Version and VersionDate with my Variable "$(Env:BUILD_BUILDNUMBER)" but it's being replaced by empty string.

  • I am using TFS 2015 with the legacy version

image

image

image

Could you provide a walkthrough?

I'm trying to enable TFS to edit the connection strings in my web.config depending on the environment it's being released to. Stack Overflow pointed out this tool, but I'm having trouble getting started. A walkthorugh document would be very helpful.

How it is kept secure?

When the Token Replacement is sent from the build task to the target file how is the data kept secure?

For example in a .config file I'm replacing a token for $(UserID) and $(Password). When these are passed to target how are they passed and how are these kept secure. Or is this data being passed as clear text?

ANSI File encoding

We have files that are losing characters. It seems to be because we have ANSI encoding (8bits) which this "Replace Tokens" does not support. ASCII is only 7bits.

See example jpg of the characters that are being replaced.
compare

May you also support ANSI?

How do we get it to run on the target server?

I am trying to run it in release management (vNext) after copying my files to the target server. How do I run this task on them? it seems like this is set up to change files on my build server.

UNC Path with glob pattern replacement

given is a UNC path like \\servername\ApplicationX

When trying to replace a file with glob pattern like **\*.config it says that it doesn't find the file.

When we map the UNC to a network drive it works. May you fix that?

Root Directory NAS location seems to fail -

Root Directory: \ \MyServer\TFSBuildDrop\DS\Dev\POAAdmin-Dev\20170602.6\drop_PublishedWebsites\POAAdmin_configs\Dev\

Target Files: *.config

returns error no file found for pattern

Evaluating environment variables

Is there a trick to get it to evaluate TFS build or release variables? For example:

tokenPrefix = __
tokenSuffix = __
regex: ((?:(?!).)*)__
Replacing tokens in file '...index.html'...
Replacing 'Version' with '$(Release.ReleaseId)'

token Version
gets replaced with the literal $(Release.ReleaseId) rather than the value of that variable.

Replace WebSettings

Hi!

I'm trying to replace in my WebSettings file the following line:

<add key="VersaoSite" value="#{Build.BuildId}#" />

I've tried the

<add key="VersaoSite" value="#{BUILD_BUILDNUMBER}#" />

as well

do i need to declare this variable as well ?

Thanks for the help

Lack of Documentation

Hi Getza,
thank you writing such a useful extension but since I am not expert in PowerShell is there any example regarding replace value in web.config?

Approach for testing locally

I was wondering what the recommended approach is for running tests locally? I've used your extension to set-up automated building in VSTS, but in some cases I like to be able to run the tests locally first just to check whether a problem was actually solved. With only the tokens in the config file now, I cannot run any tests. So I was thinking of doing some sort of Powershell script to do the same and run that as a post-build command, but I'm not sure whether that would interfere with my online build. Also, it would require me to store the token values somewhere again, getting back to the danger of accidentally checking in config files with senstive data.

Any tips on how to solve this in a good way?

Cannot use variable for Target Files

I'd like to be able to dynamically set the Target Files parameter but I can't seem to specify multiple paths when using a VSTS variable such as $(Testing) due to the delimiter being a newline character. Is there any workarounds for this?

2017-08-14T18:43:19.8807344Z ##[error]System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Name' because it is an empty string.

I am getting this error when replacing a token. The token is getting replaced but this error comes up causing the build to be partially succeded. Other builds are working fine with this step.

2017-08-14T18:43:19.8807344Z ##[error]System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'Name' because it is an empty string.

90
2017-08-14T18:43:19.8807344Z ##[error] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)

91
2017-08-14T18:43:19.8807344Z ##[error] at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)

92
2017-08-14T18:43:19.8817346Z ##[error] at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)

93
2017-08-14T18:43:19.8817346Z ##[error] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

94
2017-08-14T18:43:19.8827334Z ##[error] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Replacing connection string in web.config not working

I am encountering a bug I cannot fix.

I have this in web.release.config
image

It successfully transforms locally:
image

Have the task in place:

image

Also have the variable in place

Logs indicate that the file has been reached and successfully transformed.

After uploading, I see that all other transforms went successfully but only this one is not working.
All others are inside appSettings, that is the only difference I can spot.

image

Any idea how to fix this?

Permission issues on *nix systems

Hi,

If you use this task on a Linux system, the files become unusable after the replacement because of this line:
https://github.com/qetza/vsts-replacetokens-task/blob/master/task/index.ts#L148

Is that line something needed for Windows system? Why a permission change is needed?

I think that the files should keep the permissions they had before the replacement is done, but if this is something required on windows to work I can try to find a possible fix and make a PR, because for Linux you should set the permissions like this:

fs.chmodSync(filePath, '0666');

But IMHO that line is not needed. Do you want me to make a PR removing that line?

backslash on mac build host failing

Using backslash in Target files seems not supported when running this task on a Mac build host.
The task will not error, in ln 140 the targetFiles array seems to be empty, so nothing is printed to the log.
pasted image at 2017_11_01 02_48 pm

Does not seem to work on linux

I get error about only node handler available.

Is a way to get PowerShell on Linux yet? Presuming not...

I guess we'd need to write a node version to support this.

Cheers,
Chris

Replace group variables

Hello,
I have configured some variables groups in VSTS and tried to replace them in config files using Replace Tokens task. However, it seems this is not working. Are only process variables supported?

Thank you,
Andrei.

Leave tokens in if not found

I'd like to take a 2-phase approach in replacing variables - one during build, and one during deployment. The issue I now run into is that if the variable for a token is not found, it is replaced by an empty string. That means I cannot run the second phase since there are no more tokens to be replaced.

Would it be possible to introduce the possibility to leave tokens as-is if the corresponding variable is not found?

E.g. if I have a line
APP_FOLDER=#{Deploy.AppPath}#\#{AppFolder}#

and if Deploy.AppPath does not exist and AppFolder equals foo, then this is what I would like to end up with:

APP_FOLDER=#{Deploy.AppPath}#\foo

That would allow me to use the resulting file as input for the second phase during deployment, which is when Deploy.AppPath is defined, so that would then take care of the rest.

But at the moment, I get

APP_FOLDER=\foo

Also, it would be nice if there is an option to silently ignore unmatched tokens in the log - I expect some of them not to be found, so that doesn't require a warning.

When you enter a multi-line list of files to replace you get an error on save

400: TF20507: The string argument contains a character that is not valid:'u000A'. Correct the argument, and then try the operation again.
 Parameter name: definition.Steps.Step.DisplayName
TFS.WebApi.Exception: TF20507: The string argument contains a character that is not valid:'u000A'. Correct the argument, and then try the operation again.
Parameter name: definition.Steps.Step.DisplayName
    at d (https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:58:499)
    at https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:58:3381
    at g (https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:58:762)
    at https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:58:3314
    at l (https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:28:8126)
    at https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:28:8352
    at t.when (https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:28:3784)
    at t.u.promiseDispatch (https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:28:2828)
    at https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:28:1653
    at MessagePort.t (https://cdn.vsassets.io/bundles/vss-bundle-common-vcshZVY6RBVZ7g8rEYXk-zTcwPBhwfxZ0botyh2dkbFM=:28:5777)
Session Id: bfa30e2f-8c04-40d6-a6b0-41347f901b18

image

Tokens not replacing

I have my variables set

image

and my config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<parameters>
    <parameter name="AudienceUri" defaultValue="#{AudienceUri}#">
        <parameterEntry kind="XmlFile" scope="\\Web\.config$" match="/configuration/system.identityModel/identityConfiguration/audienceUris/add/@value" />
    </parameter>
    <parameter name="StudentSTSThumbprint" defaultValue="#{StudentSTSThumbprint}#">
        <parameterEntry kind="XmlFile" scope="\\Web\.config$" match="/configuration/system.identityModel/identityConfiguration/issuerNameRegistry/trustedIssuers/add[name='StudentSTS']/@thumbprint" />
    </parameter>
    <parameter name="Issuer" defaultValue="#{Issuer}#">
        <parameterEntry kind="XmlFile" scope="\\Web\.config$" match="/configuration/system.identityModel.services/federationConfiguration/wsFederation/@issuer" />
    </parameter>
    <parameter name="Realm" defaultValue="#{Realm}#">
        <parameterEntry kind="XmlFile" scope="\\Web\.config$" match="/configuration/system.identityModel.services/federationConfiguration/wsFederation/@realm" />
    </parameter>
    <parameter name="ApplicationName" defaultValue="#{ApplicationName}#">
        <parameterEntry kind="XmlFile" scope="\\Web\.config$" match="/configuration/exceptionManagement/publisher[type='Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher']/@applicationName" />
    </parameter>
</parameters>

My log shows the task running:

2017-04-19T20:57:39.6522145Z ##[section]Starting: Replace tokens in parameters.xml
 
2017-04-19T20:57:41.5085788Z replacing tokens in: \\cltscmnfs1\Installs\Packages\StudentSTS\3.2.0.16\StudentSTS\parameters.xml
 
2017-04-19T20:57:41.6333764Z ##[section]Finishing: Replace tokens in parameters.xml

But when I view the XML file, nothing is replaced.

Changes in Azure Cloud Services web.config

Hi,

I'm trying to apply Replace Tokens to changes in web.config in Azure Cloud Services. It isn't working because the web.config file is inside the compressed .cspkg file created in the Cloud Services build.

Is there any way to work around this issue?

Regards,
Henrique

Rev:rr replacements

Hi

I have some trouble with the $(Rev:rr) it will be not replaced.
Is there an problem with var with : ?

Getting error : Method invocation failed because [System.Char] does not contain a method named 'StartsWith'

Hi @qetza,

I get the following when the token replacement task runs through an azure worker role project. It handled .config fine without these errors in the same project but bot the task for *.cscfg.

I've copied out part of the log for your convenience:

2016-03-11T08:09:09.2950174Z Starting task: Replace tokens in $(System.DefaultWorkingDirectory)$(PackagePath)\Workers*__.cscfg

2016-03-11T08:09:09.4197945Z Executing the powershell script: C:\BuildAgent\tasks\replacetokens\1.1.0\replace-tokens.ps1

2016-03-11T08:09:10.1073335Z ##[error]Method invocation failed because [System.Char] does not contain a method named 'StartsWith'.

[... There were a hundred odd errors exactly the same as the one above which i have left out for clarity]

2016-03-11T08:09:10.3887591Z Replacing tokens in file 'C:\BuildAgent_work\35a32acd6\New.Product.CI\drop\Workers\bin\CI\app.publish\ServiceConfiguration.CloudCI.cscfg'...

2016-03-11T08:09:10.5917956Z Finishing task: replacetokens

Tokens not replaced by environment

Hi,

i use your add on on a release definition. i've one for IT, FT and staging.
I've created variable with a different value per environment.
But after replace tokens step, it's always the value of IT that are taken in count.
IT is the first environment created. How can i force to take the value linked to the environment.
Here some print screen about the situation

Release IT

image

Release FT

image

Variables

image

Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.