限制Azure DevOps Pipeline YAML中的并行作业数

时间:2019-03-06 17:57:54

标签: azure azure-devops

我们的团队正在使用YAML架构创建Azure DevOps管道来运行我们的测试脚本,并运行同一测试脚本的多次迭代。 如何告诉作业运行同一测试8次,但将并行运行的最大测试数量限制为3次?

Azure DevOps YAML Schema reference显示了一种限制运行矩阵的并行运行次数的方法:

job: Build
strategy:
  maxParallel: 2
  matrix:
    Python35:
      PYTHON_VERSION: '3.5'
    Python36:
      PYTHON_VERSION: '3.6'

但是尝试类似

job: Build
strategy:
  maxParallel: 2
  parallel: 8

引发错误,表示并行是意外标识符。

2 个答案:

答案 0 :(得分:1)

我认为它应该像这样:

jobs:
- job: xxx   
  strategy:
    parallel: 8 # parallel strategy, see below
    maxParallel: 3 # maximum number of agents to simultaneously run copies of this job on

答案 1 :(得分:1)

这有点晚了,但仍想为其他人提供答案。 如果您查看以下文档: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#define-a-single-job

它讨论了YAML作业的完整规格:

- job: string  # name of the job, A-Z, a-z, 0-9, and underscore
  displayName: string  # friendly name to display in the UI
  dependsOn: string | [ string ]
  condition: string
  strategy:
    parallel: # parallel strategy
    matrix: # matrix strategy
    maxParallel: number # maximum number simultaneous matrix legs to run
    # note: `parallel` and `matrix` are mutually exclusive
    # you may specify one or the other; including both is an error
    # `maxParallel` is only valid with `matrix`
  continueOnError: boolean  # 'true' if future jobs should run even if this job fails; defaults to 'false'
  pool: pool # agent pool
  workspace:
    clean: outputs | resources | all # what to clean up before the job runs
  container: containerReference # container to run this job inside
  timeoutInMinutes: number # how long to run the job before automatically cancelling
  cancelTimeoutInMinutes: number # how much time to give 'run always even if cancelled tasks' before killing them
  variables: { string: string } | [ variable | variableReference ] 
  steps: [ script | bash | pwsh | powershell | checkout | task | templateReference ]
  services: { string: string | container } # container resources to run as a service container

它声明'parallel' and 'matrix' are mutually exclusive。这意味着您只能将maxParallel与矩阵策略一起使用。如果没有矩阵,则必须使用“并行”。