azure - 如何从 Azure Devops 中的另一个管道有条件地运行一个管道?
问题描述
好的,所以我们正在研究微服务架构并尝试在 azure devOps 上部署代码。我们实际上只想在一个项目发生变化时触发一个管道。我们正在使用 monorepo 架构。
这就是我为项目特定的 build.yaml 添加当前条件的方式
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'))
condition 包含之前执行的 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"
}
}
所以实际的问题是,在推送到 repo 时。所有管道触发。由于添加的条件,任务确实会被跳过。但我们实际上并不想触发所有管道。
为此,我创建了一个包含 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/*
如果这没有帮助,请查看此扩展程序
推荐阅读
- git - 处理 git repos 从另一个保存历史中开发一个
- r - R (Error): x argument is missing, with no default
- pandas - Count and assign categories based on majority voting
- node.js - Information and change management of package.json vs package-lock.json in Node apps
- r - R - 在 geom_line() 中设置实际限制
- php - Move "review tab" to position output of product sharing on WooCommerce single product page
- javascript - Getting sonarlint rule error: no magic number: 1.5. Added the code below
- neo4j - Patch user Neo4j / NestJs
- c++ - C++ constructors initialization order
- css - Custom Mailchimp Embedded Suscribe Form not working in Wordpress