【问题标题】:Azure devops: How to add a parameter to a step in a steplistAzure devops:如何将参数添加到步骤列表中的步骤
【发布时间】:2022-08-18 15:08:20
【问题描述】:

我有一个模板,它采用仅在特定场景中运行的步骤列表。在模板的一部分中,stepList 可以按原样使用,但在另一部分中,我需要添加一个条件,以便在不适用时它不会运行。我尝试过的是(实际上情况更复杂,但我也尝试过):

- ${{ each step in parameters.preDeleteSteps }}:
  - ${{ each pair in step }}:
      ${{ pair.key }}: ${{ pair.value }}
  condition: succeeded()

但这失败了:

/steps/terraform.yml@templates (Line: 132, Col: 7): Expected a mapping
/steps/terraform.yml@templates (Line: 131, Col: 7): Expected at least one key-value pair in the mapping
/steps/terraform.yml@templates: Unexpected state while attempting to read the mapping end. State:

MappingState:
  IsStart: True
  Index: 0
  IsKey: False
  IsEnd: False

SequenceState:
  IsStart: False
  Index: 2
  IsEnd: False

IfExpressionState:
  IsSequenceInsertion: True
  IsStart: False

MappingState:
  IsStart: False
  Index: 0
  IsKey: True
  IsEnd: False

SequenceState:
  IsStart: False
  Index: 6
  IsEnd: False

MappingState:
  IsStart: False
  Index: 0
 [...]

我尝试了各种方法,例如将条件放在[{}] 中,在它前面放一个破折号,在每个步骤之后将它放在首位,但似乎都以错误结束。有谁知道如何做到这一点?

编辑:删除了我正在使用的实际条件,因为它不相关。我已经尝试过上述条件,但失败并出现同样的错误。

  • 当您寻求帮助时,如果您不发布屏幕截图或照片,您将获得更多/更好的答案。将文本直接剪切并粘贴到消息中。为什么? 1.人们更容易阅读。 2.它允许阅读它的人剪切和粘贴文本,从而更容易解决您的问题。 3. 使其可搜索,以便将来有人在谷歌搜索信息时可以找到此线程。 4.屏幕阅读器无法阅读限制访问我们社区中某些人的图片。

标签: azure-devops yaml


【解决方案1】:
trigger:
- none

pool:
  vmImage: ubuntu-latest

parameters:
- name: mySteplist
  type: stepList
  default:
    - task: PowerShell@2
      name: test1
      inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          Write-Host "Hello World1"
    - task: PowerShell@2
      name: test2
      inputs:
        targetType: 'inline'
        script: |
          # Write your PowerShell commands here.
          
          Write-Host "Hello World2"
        

jobs:
- job:
  displayName: testjobname
  steps:
  - ${{ each step in parameters.mySteplist }}: # Each step
    - ${{ each pair in step }}:
        ${{ pair.key }}: ${{ pair.value }}
      condition: eq(1,2) # contional expression here

这对我有用:

【讨论】:

    【解决方案2】:

    尝试打印变量的值TERRAFORM_PLAN_HAS_DESTROY_CHANGES,如果变量已经被实际定义并且具有值,那么下面的解决方案应该可以工作。你能试试吗?

     condition: and(succeeded(), eq(variables.TERRAFORM_PLAN_HAS_DESTROY_CHANGES, true))
    

    【讨论】:

    • 这不相关(虽然我没有对你投反对票)。我可能应该删除不需要的细节。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-28
    • 2022-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-06
    • 2020-06-30
    相关资源
    最近更新 更多