Azure pipeline runtime replace expression

Viewed 1437

I have two identical replace statements in the azure pipeline yaml file

 - script: echo ${{ replace('refs/heads/origin', 'refs/heads', 'origin') }}
 - script: echo $[ replace('refs/heads/origin', 'refs/heads', 'origin') ]

except for one is a runtime expression while the other one is a compile time expression.

While the compile time expression works fine run time expression is giving me following error

line 1: replace('refs/heads/origin', 'refs/heads', 'origin') : syntax error in expression (error token is "('refs/heads/origin', 'refs/heads', 'origin') ")

How do I make runtime replace expression works fine?

1 Answers

You should use a variable for this:

variables:
  runtimeTest: $[ replace('refs/heads/origin', 'refs/heads', 'origin') ]

Then you can reference it in the script part with no errors:

steps:
- script: echo $(runtimeTest)
Related