【问题标题】:Azure DevOps Pipeline decorator error on - ${{ each step in job.steps }}:Azure DevOps Pipeline 装饰器错误 - ${{ job.steps }} 中的每个步骤:
【发布时间】:2021-06-15 20:32:15
【问题描述】:

我有一个简单的管道装饰器:

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"

它会引发错误。

这是日志:

开始评估模板“BuildPreJob.yml@”

评估:工作['steps']

结果:对象

[错误]BuildPreJob.yml@(第 2 行,第 5 列):

完成评估模板'BuildPreJob.yml@'

yaml 文件中的其他内容无关紧要。只要它包含这个,它就不起作用 - ${{ each step in job.steps }}:

比如这个就不行了

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"

它引发了同样的错误。

有什么建议吗?

你知道我在哪里可以找到完整的文档吗?

这是日志:

开始评估模板“BuildPreJob.yml@”

评估:工作['steps']

结果:对象

[错误]BuildPreJob.yml@(第 2 行,第 5 列):

完成评估模板'BuildPreJob.yml@'

【问题讨论】:

  • 你检查过你的压痕吗?上面帖子中的 YAML 不一致。你似乎有太多的空间......
  • 嗨@jessehouwing 是的,我已经检查过了。它似乎没有任何缩进问题。谢谢

标签: azure-devops azure-pipelines azure-pipelines-yaml azure-pipelines-decorator


【解决方案1】:

这是整个模板文件吗?您需要一个 parameters 部分,您可以在其中声明传递给模板的作业/步骤。

这是一个工作示例(基于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! 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 2020-06-30
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    相关资源
    最近更新 更多