0

I have a simple pipeline decorator :

steps:
  - ${{ each step in job.steps }}:
    - ${{ if eq(step.task.id, '2ff763a7-ce83-4e1f-bc89-0ae63477cebe') }}:
      - task: powershell@2
        displayName: '(injected) Verify Publish Artifact task parameters'
        inputs:
          targetType: inline
          script: |
            $s = @'
            ${{convertToJson(step)}}
            '@
            $step = ConvertFrom-Json $s
            Write-Host "todo: validate the step parameters"

It raises an error.

Here is the log :

Begin evaluating template 'BuildPreJob.yml@'

Evaluating: job['steps']

Result: Object

[error]BuildPreJob.yml@ (Line: 2, Col: 5):

Finished evaluating template 'BuildPreJob.yml@'

Doesn't matter what else is in the yaml file. It doesn't work as long as it contains this - ${{ each step in job.steps }}:

For example this one doesnt work as well

steps:
  - ${{ each step in job.steps }}:
    - task: powershell@2
      displayName: '(injected) Verify each step'
      inputs:
        targetType: inline
        script: |
          Write-Host "todo: validate the step parameters"

It raises the same error.

Is there any suggestion ?

Do you know where I can find a full documentation?

here is the log :

Begin evaluating template 'BuildPreJob.yml@'

Evaluating: job['steps']

Result: Object

[error]BuildPreJob.yml@ (Line: 2, Col: 5):

Finished evaluating template 'BuildPreJob.yml@'

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Shahyad Sharghi
  • 660
  • 9
  • 12

1 Answers1

1

Is that the whole template file? You need a parameters section, where you would declare jobs/steps passed to your template.

Here's a working example (based on templates docs):

# decorator.yaml

parameters:
  - name: "jobs"
    type: jobList
    default: []

jobs:
  - ${{ each job in parameters.jobs }}: # Each job
    - ${{ each pair in job }}:          # Insert all properties other than "steps"
        ${{ if ne(pair.key, 'steps') }}:
          ${{ pair.key }}: ${{ pair.value }}
      steps:
        - ${{ each step in job.steps }}:
          - pwsh: |
              $s = @'
              ${{convertToJson(step)}}
              '@
              write-host "step as json:"
              Write-Host $s
            displayName: "(injected) debug step"
          - ${{ step }}
# pipeline.yaml
variables:
  system.debug: true

stages:
  - stage: decorated
    jobs:
      - template: decorator.yaml
        parameters:
          jobs:
          - job: A
            steps:
            - script: echo something really fancy.
          - job: B
            steps:
            - script: echo and another! 
qbik
  • 5,502
  • 2
  • 27
  • 33