Azure DevOps 管道任务等待 运行 另一个管道完成

Azure DevOps pipeline task to wait to run for another pipeline to complete

我对 Azure DevOps 管道和任务有疑问,想知道是否有人可以提供帮助。

我有一个管道,其任务是 运行PowerShell 脚本。这个脚本启动了一个单独的管道,但是一旦该脚本是 运行,原始任务 returns 一个 "pass"(如预期的那样)并且原始管道中的下一个任务开始 运行.

理想情况下,我希望管道 1 中的下一个任务等到脚本启动的管道完成(并且 returns 通过)。有谁知道可以实现这一目标的方法?这些步骤使用 YAML。到目前为止,我已经看到了等待同一管道中其他步骤的条件,但是在完全独立的管道完成(并成功通过)之前,没有什么可以阻止 运行ning 的步骤。

希望我说得有道理。如果有帮助,我可以提供屏幕截图!

您可以安装 Trigger Build Task 扩展并使用它,而不是使用您的 PowerShell 脚本触发构建。你有一个选项等到触发的构建完成后再继续构建:

在 YAML 中:

- task: TriggerBuild@3
  displayName: 'Trigger a new build of Test'
  inputs:
    buildDefinition: Test
    waitForQueuedBuildsToFinish: true
    waitForQueuedBuildsToFinishRefreshTime: 60

If this option is enabled, the script will wait until the all the queued builds are finished. Note: This can take a while depending on your builds and your build will not continue. If you only have one build agent you will even end up in a deadlock situation!

根据描述,整个过程可以分为四个部分:

  1. Pipeline1 中的任务 1 应该会触发 Pipeline2 中的任务,如果 Pipeline 中的任务不可编辑,您可能需要最后在其中创建一个新任务以供下一步使用

  2. Pipeline2 中的最后一个任务应该做一些事情,比如在特定文件夹中创建一个 txt 文件或任何其他可以被 Pipeline1 中的 task2 检测到的东西

  3. Pipeline1 中的 task2 应该等待并监听是否在文件夹中创建了一个 txt 文件,这意味着 Pipeline1 已成功完成。

  4. 运行任务2

您在这里面临的主要问题是所有变量都是使用 YAML 在队列上求值的。

您可以做一些事情,例如利用 Azure 存储帐户等外部服务。这样做您可以做其他事情,例如将管道中的注释或状态写入文本文件并将值读入您的第一个管道。

管道 1 中脚本 1 的末尾:

Do {
   $File = check for storage account file
   if ($File) {
      $FileExists = $true
   }
} until ($FileExists)

在你的另一个管道的末端

Do stuff
Write stuff to file
Upload file to storage account

如果您只想等待完成,您可以在第一个 powershell 步骤结束时使用 azure devops cli。这是一个很好的 link: https://techcommunity.microsoft.com/t5/ITOps-Talk-Blog/Get-Azure-Pipeline-Build-Status-with-the-Azure-CLI/ba-p/472104 。您可以 运行 您对返回的 statusresult

的逻辑