Azure 管道运行时替换表达式

时间:2021-07-21 08:31:18

标签: azure azure-devops azure-pipelines

我在 azure 管道 yaml 文件中有两个相同的 replace 语句

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

除了一个是运行时表达式,另一个是编译时表达式。

虽然编译时表达式工作正常,但运行时表达式给了我以下错误

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

如何使运行时替换表达式正常工作?

1 个答案:

答案 0 :(得分:1)

您应该为此使用一个变量:

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

然后您可以在 script 部分中引用它而不会出错:

steps:
- script: echo $(runtimeTest)
相关问题