Azure DevOps YAML管道手动干预作业与其他作业并行运行

时间:2020-02-07 12:49:37

标签: azure-devops yaml

我希望这些作业接连进行,并且第一个作业应控制下一个作业的执行。

由于YAML管道中目前尚无批准在Kubernetes之外进行部署,因此我正在使用“手动干预”来停止该作业的运行。但是显然,它并没有停止工作,而是停止了即将到来的阶段。我做错了什么?我希望收到有关干预措施的通知,但它会立即失败,并且根本不会停止下一项工作。

enter image description here

这是Deploy STG阶段的代码的一部分,其中parameters.interventionEnabled设置为true

jobs:
- job: RunOnServer
  displayName: 'Reject or resume'
  pool: server
  continueOnError: false
  steps:
  - task: ManualIntervention@8
    displayName: 'Manual Intervention'
    timeoutInMinutes: 0
    inputs:
      instructions: 'reject or resume'
    enabled: ${{ parameters.interventionEnabled }}

- job: Deploy
  displayName: ${{ parameters.name }}
  pool:
    name: ${{ parameters.agentPoolName }}
  steps:
  - checkout: none # skip checking out the default repository resource

  - task: DownloadPipelineArtifact@2
    displayName: Download NPM build artifact
    inputs:
      artifact: ${{ parameters.artifactName }}
      buildType: 'current'
      targetPath: ${{ parameters.artifactPath }}

2 个答案:

答案 0 :(得分:4)

嘿,Andree ManualIntervention@8在YAML中不受支持。它是2020\Q2的映射。

我认为您想走的路线是将approvalsgeneric environment types一起使用。

因此您可以像这样在Yaml中定义deployment job和环境

- deployment: DeploymentHosted Context
  displayName: Runs in Hosted Pool
  pool:
    vmImage: 'Ubuntu-16.04'
  # creates an environment if it doesn't exist
  environment: 'Dev'
  strategy:
    runOnce:
      deploy:
        steps:
        - bash: |
            echo This multiline script always runs in Bash.
            echo Even on Windows machines!

然后使用GUI保护环境。

  • 导航到管道-> 环境
  • 选择环境(您可以预先创建它们)。
  • 然后添加并批准

    approvals menu

approvals

与经典发行版定义相比,并且能够手动触发到阶段有一些缺点。您可能不希望每个工件都适合每个阶段,并且,如果您不批准该环境,最终将导致超时并报告失败。 comments here中的其他精彩讨论。

答案 1 :(得分:1)

现在可用: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/manual-validation?view=azure-devops&tabs=yaml

- task: ManualValidation@0
  timeoutInMinutes: 1440 # task times out in 1 day
  inputs:
    notifyUsers: |
      test@test.com
      example@example.com
    instructions: 'Please validate the build configuration and resume'
    onTimeout: 'resume'