OK, so we are working on the micro service architecture and trying to deploy the code on azure devOps. we actually only want to trigger one pipeline when one project is changed. we are using a monorepo architecute.
This is how i have added the condition currently for the project specific 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 contains the variable SmsMessaging from the powershell script that is executed before.
$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"
}
}
So the actual problem is that, on pushing to the repo. all the pipelines trigger. Tasks do get skipped because of the condition that's been added. But we actually don't want to trigger all the pipelines.
For that, I have created a main pipeline that would have the powerShell script and variables. and will conditionally trigger the other pipelines.
But I am unable to add a "condition" to this 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)
is this the right approach ?Any help is appreciated. Thanks
EDIT : I Also tried to login and trigger the pipelines through Powershell.
Invoke-AzDataFactoryV2Pipeline -ResourceGroupName "RGName" -DataFactoryName "FactoryName" -PipelineName "PipelineName"
but it doesnt allow me to run the pipeline saying that Organization ID is required.
You can combine your approach with path filters. You can trigger the build using path triggers in your monorepo architecture Something like:
trigger:
branches:
include:
- master
paths:
include:
- path/to/SmsMessaging/*
If this does not help, have a look at this extension