qetza / replacetokens-task

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

Support for task variables #46

Closed ThibaultLesuisse closed 1 month ago

ThibaultLesuisse commented 1 month ago

My use case is pretty straight forward (I think). I generate an image version dynamically and export it as a task variable.

- powershell:  ##vso[task.setvariable variable=image_version]$ImageVersion
- task: replacetokens@6
  inputs:
    sources: 'values.pkrvars.hcl'
    additionalVariables: 'image_version: $(image_version)'
    logLevel: 'debug'

Is something like this possible? Or am I not reading the docs right?

qetza commented 1 month ago

Hi @ThibaultLesuisse, If you set your variable before calling the task then no need to specify it in additionalVariables, all variables are automatically accessible. additionalVariables is more to be used if you need to import parameters or variables stored in files.

That said you have a syntax error, to set a variable you need to output the command ##vso[...:

- powershell:  'Write-Host "##vso[task.setvariable variable=image_version]$ImageVersion"'
- task: replacetokens@6
  inputs:
    sources: 'values.pkrvars.hcl'
    logLevel: 'debug'
ThibaultLesuisse commented 1 month ago

Hi @qetza,

That was indeed the issue and for reference your library will indeed also look at the task variables for token subsitution!

Thank you very much for you support!