Azure管道任务:手动验证将参数传递到输入

huangapple go评论62阅读模式
英文:

Azure pipeline task: ManualValidation passing parameter into input

问题

我尝试了许多变化但没有成功。

我正在尝试实现此功能,但是使用了电子邮件地址和组的参数:

这个有效:

steps:
      - task: ManualValidation@0
        timeoutInMinutes: 1440 # 任务超时时间为1天
        inputs:
          onTimeout: reject
          notifyUsers: |
            [muttsMitts]\release_group
            admin@muttsMitts.com            
          instructions: '请验证构建配置并继续'

带有参数
创建一个字符串作为变量,循环,只传递原始对象。

parameters:
  - name: 'emailList'
    type: object
    default:
      - '[muttsMitts]\release_group' # 我必须在字符串周围加引号
      - [muttsMitts]\release_group

 - job: manual_approval
      displayName: "手动批准"
      pool: server
      timeoutInMinutes: 4320 # 作业超时时间为3天
      variables:
        - name: emailList
          value: ${{join(', ', parameters.emailList)}}
      steps:
      - task: ManualValidation@0
        timeoutInMinutes: 1440 # 任务超时时间为1天
        inputs:
          onTimeout: reject
          notifyUsers: |
            ${{each email in parameters.emailList}}
              ${{email}}            
          instructions: '请验证构建配置并继续'

返回错误:

在解析管道YAML时遇到错误:
/azure-pipelines.yml (第96行,第24列):在此上下文中不允许使用指令“each”。指令不受嵌入在字符串中的表达式支持。只有当整个值都是一个表达式时,才支持指令。
英文:

I've tried many variations but without success.

I am trying to achieve this functionality but using a parameter of emai addresses and groups:

This works:

steps:
      - task: ManualValidation@0
        timeoutInMinutes: 1440 # task times out in 1 day 
        inputs:
          onTimeout: reject
          notifyUsers: |
            [muttsMitts]\release_group
            admin@muttsMitts.com
          instructions: 'Please validate the build configuration and resume'

With parameter
Creating a string as a variable, looping, passing just the original object.

parameters:
  - name: 'emailList'
    type: object
    default:
      - '[muttsMitts]\release_group' # I have to put the quotes around the string
      - [muttsMitts]\release_group

 - job: manual_approval
      displayName: "Manual Approval"
      pool: server
      timeoutInMinutes: 4320 # job times out in 3 days
      variables:
        - name: emailList
          value: ${{join(', ', parameters.emailList)}}
      steps:
      - task: ManualValidation@0
        timeoutInMinutes: 1440 # task times out in 1 day 
        inputs:
          onTimeout: reject
          notifyUsers: |
            ${{each email in parameters.emailList}}
              ${{email}}
          instructions: 'Please validate the build configuration and resume'

Returns error:

Encountered error(s) while parsing pipeline YAML:
/azure-pipelines.yml (Line: 96, Col: 24): The directive 'each' is not allowed in this context. Directives are not supported for expressions that are embedded within a string. Directives are only supported when the entire value is an expression.

答案1

得分: 0

你可以始终使用一个字符串,并将参数值传递进去。

在可重用的作业中,只需定义一个字符串参数:

# job.yaml
parameters:
- name: notifyUsers
  type: string
  default: ''''

jobs:
- job: manual_approval
  displayName: Manual Approval
  pool: server
  timeoutInMinutes: 4320 # 作业超时时间为3天
  steps:
  - task: ManualValidation@0
    timeoutInMinutes: 1440 # 任务超时时间为1天 
    inputs:
      onTimeout: reject
      notifyUsers: ${{ parameters.notifyUsers }}
      instructions: 请验证构建配置并继续

然后可以这样调用它:

jobs:
- template: ./job.yaml
  parameters:
    notifyUsers: |
      [muttsMitts]\release_group
      admin@muttsMitts.com

如果你想使用数组,你的方法也可以。只需在换行处进行连接:

# job.yaml
parameters:
- name: notifyUsers
  type: object
  default: []

jobs:
- job: manual_approval
  displayName: Manual Approval
  pool: server
  timeoutInMinutes: 4320 # 作业超时时间为3天
  steps:
  - task: ManualValidation@0
    timeoutInMinutes: 1440 # 任务超时时间为1天 
    inputs:
      onTimeout: reject
      notifyUsers: ${{ join(''\n'', parameters.notifyUsers) }}
      instructions: 请验证构建配置并继续

然后像这样调用它:

resources:
- repo: self

trigger: none
pr: none

jobs:
- template: ./job.yaml
  parameters:
    notifyUsers:
    - ''[muttsMitts]\release_group''
    - ''admin@muttsMitts.com''
英文:

You could always use a string and just pass through the parameter value.

In your reusable job, just define a string parameter:

# job.yaml
parameters:
- name: notifyUsers
  type: string
  default: ''

jobs:
- job: manual_approval
  displayName: Manual Approval
  pool: server
  timeoutInMinutes: 4320 # job times out in 3 days
  steps:
  - task: ManualValidation@0
    timeoutInMinutes: 1440 # task times out in 1 day 
    inputs:
      onTimeout: reject
      notifyUsers: ${{ parameters.notifyUsers }}
      instructions: Please validate the build configuration and resume

Then you can invoke it like that:

jobs:
- template: ./job.yaml
  parameters:
    notifyUsers: |
      [muttsMitts]\release_group
      admin@muttsMitts.com

If you'd like to use an array, your approach works. you just need to have a join on line break:

# job.yaml
parameters:
- name: notifyUsers
  type: object
  default: []

jobs:
- job: manual_approval
  displayName: Manual Approval
  pool: server
  timeoutInMinutes: 4320 # job times out in 3 days
  steps:
  - task: ManualValidation@0
    timeoutInMinutes: 1440 # task times out in 1 day 
    inputs:
      onTimeout: reject
      notifyUsers: ${{ join('\n', parameters.notifyUsers) }}
      instructions: Please validate the build configuration and resume

Then invoke it like that:

resources:
- repo: self

trigger: none
pr: none

jobs:
- template: ./job.yaml
  parameters:
    notifyUsers:
    - '[muttsMitts]\release_group'
    - 'admin@muttsMitts.com'

huangapple
  • 本文由 发表于 2023年6月27日 19:09:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564250.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定