【问题标题】:Azure pipeline runtime replace expressionAzure 管道运行时替换表达式
【发布时间】:2021-07-21 08:31:18
【问题描述】:

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

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

【问题讨论】:

    标签: azure azure-devops azure-pipelines


    【解决方案1】:

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

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

    然后你可以在script部分引用它,没有错误:

    steps:
    - script: echo $(runtimeTest)
    

    【讨论】:

    • 酷,它适用于硬编码值,谢谢。你能告诉我如何使用 PredefiinedVariables $[replace(variables['System.PullRequest.TargetBranch'], 'refs/heads', 'origin')] 返回 refs/heads/master
    • 它应该适用于您使用的语法。请注意,根据System.PullRequest.TargetBranch 的文档:“仅当构建由于受分支策略影响的 Git PR 而运行时才初始化此变量。如果 PR 受分支策略影响,此变量仅在 YAML 管道中可用。” docs.microsoft.com/en-us/azure/devops/pipelines/build/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多