如何在Azure Devops中有条件地从另一个管道运行一个管道?
好的,我们正在研究微服务架构,并尝试在azure devOps上部署代码。实际上,我们只希望在一个项目发生更改时触发一个管道。我们使用的是monorepo架构 这就是我目前为特定于项目的build.yaml添加条件的方式如何在Azure Devops中有条件地从另一个管道运行一个管道?,azure,azure-devops,microservices,Azure,Azure Devops,Microservices,好的,我们正在研究微服务架构,并尝试在azure devOps上部署代码。实际上,我们只希望在一个项目发生更改时触发一个管道。我们使用的是monorepo架构 这就是我目前为特定于项目的build.yaml添加条件的方式 name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r) steps: # for PowerShell Core - pwsh: ./build
name: $(TeamProject)_$(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
steps:
# for PowerShell Core
- pwsh: ./build.ps1
# Restore sms-messaging micro service projects
- task: DotNetCoreCLI@1
displayName: Run dotnet restore
inputs:
command: "restore"
projects: sms-messaging/src/**/*.csproj
condition: and(succeeded(), eq(variables['SmsMessaging'], 'True'))
条件包含之前执行的powershell脚本中的变量SmsMessaging
$files=$(git diff HEAD HEAD~ --name-only)
$temp=$files -split ' '
$count=$temp.Length
echo "Total changed $count files"
For ($i=0; $i -lt $temp.Length; $i++)
{
$name=$temp[$i]
echo "this is $name file"
if ($name -like "sms-messaging/*")
{
echo "changes in sms-messaging"
Write-Host "##vso[task.setvariable variable=SmsMessaging]True"
}
}
因此,实际问题是,在推动回购协议时。所有的管道都会触发。由于添加了条件,任务确实会被跳过。但我们实际上不想触发所有的管道
为此,我创建了一个包含powerShell脚本和变量的主管道。并有条件地触发其他管道
但我无法在yaml中添加“条件”
resources:
pipelines:
- pipeline: SmsMessaging
project: SmsMessaging
source: SmsMessaging
trigger:
branches:
include:
- master
(i want to add condition here maybe if thats possible ? and trigger different pipelines from here. Or if there is another approach)
这是正确的方法吗?感谢您的帮助。谢谢
编辑:我还尝试通过Powershell登录并触发管道
Invoke-AzDataFactoryV2Pipeline -ResourceGroupName "RGName" -DataFactoryName "FactoryName" -PipelineName "PipelineName"
但是它不允许我运行管道说需要组织ID。您可以将您的方法与路径过滤器相结合。您可以在monorepo体系结构中使用路径触发器触发构建,例如:
trigger:
branches:
include:
- master
paths:
include:
- path/to/SmsMessaging/*
如果这没有帮助,请查看此这将仅触发修改文件的生成?我试试看。谢谢是的,仅当指定路径下的文件发生更改时才会触发生成。谢谢!这起作用了。我首先分离了所有管道的分支,现在我根据路径添加了触发器。太好了。很高兴知道。:)