Viv*_*Dev 7 azure-devops azure-pipelines azure-pipelines-yaml
最近正在研究 Azure DevOps 模板。并遇到了这种双花括号语法。只是想知道如何在 Azure DevOps 中使用双花括号。
看过一些关于相同内容的帖子。
可以说,我在组中定义了一个变量,如下所示。
我们还可以在 yaml 文件中定义变量,如下所示。
variables:
- name: BuildConfiguration
value: 'Release'
- name: finalBuildArtifactName
value: 'TempFolderName'
Run Code Online (Sandbox Code Playgroud)
什么时候应该使用双大括号语法?
我有关于并使用以下方法来引用变量的想法。
与上述两个相比,我们可以用双花括号完成什么?
让 yaml 管道中的东西正常工作非常困难。进行更改、签入、运行管道、查看结果并再次返回。这非常耗时,而且至少可以说并不顺利。
Krz*_*tof 10
${{}}语法用于表达式。更何况还有一个$[ <expression> ]。区别如下:
# Two examples of expressions used to define variables
# The first one, a, is evaluated when the YAML file is compiled into a plan.
# The second one, b, is evaluated at runtime.
# Note the syntax ${{}} for compile time and $[] for runtime expressions.
variables:
a: ${{ <expression> }}
b: $[ <expression> ]
Run Code Online (Sandbox Code Playgroud)
请在此处查看文档。
正如你可能在这里看到的
steps:
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Pipeline.Workspace)'
${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
artifact: 'prod'
${{ else }}:
artifact: 'dev'
publishLocation: 'pipeline'
Run Code Online (Sandbox Code Playgroud)
您可以使用variables['Build.SourceBranchName']语法来访问变量。但,
variables:
- name: foo
value: fabrikam # triggers else condition
pool:
vmImage: 'ubuntu-latest'
steps:
- script: echo "start"
- ${{ if eq(variables.foo, 'adaptum') }}:
- script: echo "this is adaptum"
- ${{ elseif eq(variables.foo, 'contoso') }}:
- script: echo "this is contoso"
- ${{ else }}:
- script: echo "the value is not adaptum or contoso"
Run Code Online (Sandbox Code Playgroud)
您也可以使用variables.foo.
表达式通常用于条件评估、动态步骤/作业/阶段配置等。
| 归档时间: |
|
| 查看次数: |
6756 次 |
| 最近记录: |