1

I have the following yml expression in my pipeline template:

- {{ each step in job.steps }}:
    - {{each pair in step}}:
        {{if startsWith(pair.key, 'DotNetCoreCLI@')}}:
          - powershell: |
              ## run some powershell commands here

This scans through all the steps in a job and adds a powershell task in the job if there is any DotNetCoreCLI task. The issue is, if there are multiple DotNetCoreCLI tasks in this job, the powershell task is also added multiple times. I can add conditions so that the powershell task only runs once, but it still shows up multiple times in build timeline.

Is there any way I can just add this task once if there is any DotNetCoreCLI task in the job?

1 Answers1

0

I haven't tested this myself but instead of using the:

- {{ each step in job.steps }}:
   - {{each pair in step}}:

you can use something like

- ${{ if (containsValue(job.steps.*.task.name, 'DotNetCoreCLI')) }}:
  - powershell: |
        ## run some powershell commands here

You can find a similar example in the documentation.

matei.navidad
  • 676
  • 6
  • 18