问题描述
我们有2条管道
管道1:
- 将我们的代码分支构建并部署到server1
- 通过执行dotnet运行命令来启动.exe
管道2:
- 从服务器2运行测试脚本并将请求发送到在管道1中在服务器1上启动的exe
- 停止服务器上的.exe1
目标是将这2条管道合并为1条,或者一键单击两个管道将在管道1开始的地方运行,然后在管道2开始的地方运行。实现这一目标的最佳方法是什么?请注意,由于.exe正在运行,因此不认为管道1是完整的。
解决方法
一个选项是保持原样,并在管道1中添加步骤以在REST API上触发管道2。
https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.0
有这个身体
{
"definition": {
"id": 217
},"sourceBranch": "refs/heads/master","sourceVersion": "","reason": 1,"demands": [],"parameters": "{\"system.debug\":\"true\"}"
}
({here,您有一个示例如何通过powershell任务执行此操作)
或带有扩展名Trigger Azure DevOps Pipeline
您还可以尝试将这两个管道合并为一个使用阶段。要并行运行两个阶段,您需要使它们独立运行,例如this:
stages:
- stage: FunctionalTest
jobs:
- job:
...
- stage: AcceptanceTest
dependsOn: [] # this removes the implicit dependency on previous stage and causes this to run in parallel
jobs:
- job:
...
然后,如果您触发管道,则两个阶段都将运行。
第三种选择是使用pipeline triggers,但是对于这种方法,我建议您在第一个管道中创建两个阶段并使用stage filter。
,您可以尝试以下解决方法,将2条管道合并为1条。
在管道1中,您可以打开另一个命令终端以启动.exe。对于下面的示例,在powershell脚本中使用Start-Process:
当powershell任务完成以下命令执行时,Start-Process powershell -ArgumentList "dotnet run ..."
命令将在新的poweshell窗口中执行,并且管道将继续执行以下任务。
steps:
- powershell: |
Start-Process powershell -ArgumentList "dotnet run ..."
- task: PowerShellOnTargetMachines@3
inputs:
Machines: 'server2'
UserName: 'userName'
UserPassword: '123456'
InlineScript: |
# Write your powershell commands here.
- powershell: |
Stop-Process -Name processName
然后,您可以在管道1中添加PowerShell on target machines或SSH Deployment task以在服务器2上运行测试脚本。
请参见以下简单示例:
{{1}},
如果已经配置了两个管道并分别运行,并且这是所需的状态,则让一个管道完成触发下一个管道。可以使用Pipeline Triggers
resources:
pipelines:
- pipeline: Pipeline1 # Name of the pipeline resource
source: Pipeline1Name # Name of the pipeline referenced by the pipeline resource
trigger:
branches:
- releases/*
- master
Pipeline1是您的YAML用来引用管道资源的名称,类似于另一个存储库中的模板。
源将是Azure Devops中定义的管道的名称。