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

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

Azure pipeline task: ManualValidation passing parameter into input

问题

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

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

这个有效:

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

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

  1. parameters:
  2. - name: 'emailList'
  3. type: object
  4. default:
  5. - '[muttsMitts]\release_group' # 我必须在字符串周围加引号
  6. - [muttsMitts]\release_group
  7. - job: manual_approval
  8. displayName: "手动批准"
  9. pool: server
  10. timeoutInMinutes: 4320 # 作业超时时间为3天
  11. variables:
  12. - name: emailList
  13. value: ${{join(', ', parameters.emailList)}}
  14. steps:
  15. - task: ManualValidation@0
  16. timeoutInMinutes: 1440 # 任务超时时间为1天
  17. inputs:
  18. onTimeout: reject
  19. notifyUsers: |
  20. ${{each email in parameters.emailList}}
  21. ${{email}}
  22. instructions: '请验证构建配置并继续'

返回错误:

  1. 在解析管道YAML时遇到错误:
  2. /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:

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

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

  1. parameters:
  2. - name: 'emailList'
  3. type: object
  4. default:
  5. - '[muttsMitts]\release_group' # I have to put the quotes around the string
  6. - [muttsMitts]\release_group
  7. - job: manual_approval
  8. displayName: "Manual Approval"
  9. pool: server
  10. timeoutInMinutes: 4320 # job times out in 3 days
  11. variables:
  12. - name: emailList
  13. value: ${{join(', ', parameters.emailList)}}
  14. steps:
  15. - task: ManualValidation@0
  16. timeoutInMinutes: 1440 # task times out in 1 day
  17. inputs:
  18. onTimeout: reject
  19. notifyUsers: |
  20. ${{each email in parameters.emailList}}
  21. ${{email}}
  22. instructions: 'Please validate the build configuration and resume'

Returns error:

  1. Encountered error(s) while parsing pipeline YAML:
  2. /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

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

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

  1. # job.yaml
  2. parameters:
  3. - name: notifyUsers
  4. type: string
  5. default: ''''
  6. jobs:
  7. - job: manual_approval
  8. displayName: Manual Approval
  9. pool: server
  10. timeoutInMinutes: 4320 # 作业超时时间为3天
  11. steps:
  12. - task: ManualValidation@0
  13. timeoutInMinutes: 1440 # 任务超时时间为1天
  14. inputs:
  15. onTimeout: reject
  16. notifyUsers: ${{ parameters.notifyUsers }}
  17. instructions: 请验证构建配置并继续

然后可以这样调用它:

  1. jobs:
  2. - template: ./job.yaml
  3. parameters:
  4. notifyUsers: |
  5. [muttsMitts]\release_group
  6. admin@muttsMitts.com

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

  1. # job.yaml
  2. parameters:
  3. - name: notifyUsers
  4. type: object
  5. default: []
  6. jobs:
  7. - job: manual_approval
  8. displayName: Manual Approval
  9. pool: server
  10. timeoutInMinutes: 4320 # 作业超时时间为3天
  11. steps:
  12. - task: ManualValidation@0
  13. timeoutInMinutes: 1440 # 任务超时时间为1天
  14. inputs:
  15. onTimeout: reject
  16. notifyUsers: ${{ join(''\n'', parameters.notifyUsers) }}
  17. instructions: 请验证构建配置并继续

然后像这样调用它:

  1. resources:
  2. - repo: self
  3. trigger: none
  4. pr: none
  5. jobs:
  6. - template: ./job.yaml
  7. parameters:
  8. notifyUsers:
  9. - ''[muttsMitts]\release_group''
  10. - ''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:

  1. # job.yaml
  2. parameters:
  3. - name: notifyUsers
  4. type: string
  5. default: ''
  6. jobs:
  7. - job: manual_approval
  8. displayName: Manual Approval
  9. pool: server
  10. timeoutInMinutes: 4320 # job times out in 3 days
  11. steps:
  12. - task: ManualValidation@0
  13. timeoutInMinutes: 1440 # task times out in 1 day
  14. inputs:
  15. onTimeout: reject
  16. notifyUsers: ${{ parameters.notifyUsers }}
  17. instructions: Please validate the build configuration and resume

Then you can invoke it like that:

  1. jobs:
  2. - template: ./job.yaml
  3. parameters:
  4. notifyUsers: |
  5. [muttsMitts]\release_group
  6. admin@muttsMitts.com

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

  1. # job.yaml
  2. parameters:
  3. - name: notifyUsers
  4. type: object
  5. default: []
  6. jobs:
  7. - job: manual_approval
  8. displayName: Manual Approval
  9. pool: server
  10. timeoutInMinutes: 4320 # job times out in 3 days
  11. steps:
  12. - task: ManualValidation@0
  13. timeoutInMinutes: 1440 # task times out in 1 day
  14. inputs:
  15. onTimeout: reject
  16. notifyUsers: ${{ join('\n', parameters.notifyUsers) }}
  17. instructions: Please validate the build configuration and resume

Then invoke it like that:

  1. resources:
  2. - repo: self
  3. trigger: none
  4. pr: none
  5. jobs:
  6. - template: ./job.yaml
  7. parameters:
  8. notifyUsers:
  9. - '[muttsMitts]\release_group'
  10. - '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:

确定