[英]Azure DevOps Pipelines Expressions
Goal is to condition a task custom extension based on which task is used in pipeline.目标是根据管道中使用的任务来调整任务自定义扩展。 For that we want to use pipelines decorators
为此,我们想使用管道装饰器
For example, if any user is using Powershell task in their pipelines, we want to execute our task with decorators.例如,如果任何用户在他们的管道中使用 Powershell 任务,我们希望使用装饰器执行我们的任务。
But we can figure out how to make it works.但我们可以弄清楚如何让它发挥作用。
Yaml: Yaml:
steps:
- ${{ if and(eq(resources.repositories['self'].ref, r esources.repositories['self'].defaultBranch), not(containsValue(job.steps.*.task.id, 'd9bafed4-0b18-4f58-968d-86655b4d2ce9'))) }}:
- script: dir
displayName: 'Run my script (injected from decorator)'
Directly from Microsoft tutorial直接来自微软教程
Inside Azure DevOps Pipelines, visual editor brings this error:在 Azure DevOps Pipelines 内部,可视化编辑器会出现此错误:
Unexpected property ${{ if containsValue(job.steps.*.task.id, '1c524b9b-9f4d-4897-8f1e-6ec33271d75c') }}
The first property must be task第一个属性必须是任务
And at runtime:在运行时:
We also tried with condition()
:我们还尝试了
condition()
:
condition: |
and
(
eq(dependencies.A.result, 'Succeeded'),
containsValue(dependencies.A.steps.*.task.id, '1c524b9b-9f4d-4897-8f1e-6ec33271d75c')
)
But we can't find correct syntax, object content is null:但是我们找不到正确的语法,object 的内容是 null:
Anyone know how to retrieve task id and use it to condition any further task?任何人都知道如何检索任务 ID 并使用它来调节任何进一步的任务?
You should put the expression in your Decorator YAML file , not the pipeline azure-pipelines.yml file.您应该将表达式放在装饰器 YAML 文件中,而不是管道 azure-pipelines.yml 文件中。 To get started with Pipeline Decorators, you need to follow the following steps:
要开始使用管道装饰器,您需要执行以下步骤:
You cam get more details from the following blog:您可以从以下博客获得更多详细信息:
https://soltisweb.com/blog/detail/2019-11-07-simplifying-azure-devops-pipelines-with https://soltisweb.com/blog/detail/2019-11-07-simplifying-azure-devops-pipelines-with
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.