Azure管道运行时替换表达式

标签 azure azure-devops azure-pipelines

我在 azure pipeline 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') ")

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

最佳答案

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

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

然后您可以在 script 部分引用它,不会出现错误:

steps:
- script: echo $(runtimeTest)

关于Azure管道运行时替换表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68466365/

相关文章:

c# - Azure Web PubSub 和事件网格/事件中心之间有什么区别?

c# - 将网站和类库部署到 Azure

sql-server - AzureDevOps 管道和 sqlpackage

azure - 通过 API 返回托管代理使用情况?

azure-devops - Azure DevOps 部署组 - 是否可以忽略离线目标?

Azure管道-terratest-错误: Please run 'az login' to setup account

Azure cron 管道始终运行

Azure API - 如何查明虚拟机是否正在运行或已解除分配

nuget - VSTS 构建定义 : adding multiple feeds in Nuget restore task

azure - 使用 ADOMD.NET 连接到 Azure Analysis 时出现连接字符串错误