qetza/replacetokens-task

Support for task variables

Closed this issue · 2 comments

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?

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'

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!