gab
gab

Reputation: 83

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.

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 :

error

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 :

object_null

Anyone know how to retrieve task id and use it to condition any further task ?

Upvotes: 1

Views: 943

Answers (1)

Cece Dong - MSFT
Cece Dong - MSFT

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:

  • Create an extension file. This defines the type of extension, as well as the packaged files.
  • Create a YAML file. This file contains the steps you want to execute for each pipeline.
  • Create an HTML file. This will be displayed when a user views your extension in the Marketplace.
  • Package the extension. This creates a .VSIX file you will use to register your extension.
  • Register your extension. This involves uploading your file to the Azure DevOps Marketplace and making it available to your Azure DevOps Organization.
  • Add the extension to your org. This allows the extension to be applied to your pipelines.

You cam get more details from the following blog:

https://soltisweb.com/blog/detail/2019-11-07-simplifying-azure-devops-pipelines-with

Upvotes: 1

Related Questions