Reputation: 83
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.
But we can figure out how to make it works.
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 :
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: |
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 :
Anyone know how to retrieve task id and use it to condition any further task ?
Upvotes: 1
Views: 943
Reputation: 31023
You should put the expression in your Decorator YAML file, not the pipeline azure-pipelines.yml file. 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
Upvotes: 1