qetza / replacetokens-task

Azure Pipelines task to replace tokens in files with variables.
MIT License
11 stars 2 forks source link

[Question] Any escape options? #28

Closed kirill-d-lappo closed 4 months ago

kirill-d-lappo commented 4 months ago

Does the task support escaping?

In my case I have kubernetes manifest file, where I replace values in labels.

But I have problems when value of a variable contains double quotes.

For example:

label: "${LABEL_VALUE}"

with

LABEL_VALUE='text with "quoted" word'

will result in invalid yaml file.


task version: 5

qetza commented 4 months ago

Hi @kirill-d-lappo, Yes it's possible to define custom escaping.

The following inputs will escape backslashes \ and double quotes " with a backslash \:

- task: replacetokens@5
  inputs:
    targetFiles: manifest.yml
    escapeType: custom
    escapeChar: '\'
    charsToEscape: '\"'
    tokenPattern: custom
    tokenPrefix: '${'
    tokenSuffix: '}'

Due to how the custom escaping is done it's important to set the escape character as the first character in charsToEscape.

kirill-d-lappo commented 4 months ago

thanks!