2

I am working on a large scale application which uses multiple small-small project/solutions. Each solution is built in their respective agents. Similar to below screenshot enter image description here

Now the problem is that all the projects/solutions are compiled even if a single project file is changed.

To reduce CI build time, I want to add conditional expression in the build which would build the project only if their respective source is changed.

I know this can be achieved in Azure DevOps via Custom condition using variable expressions. But I am not sure how can I check if the respective source code is changed enter image description here

Does anyone know what variable expression I need to write here?

Abhishek
  • 621
  • 1
  • 8
  • 19

2 Answers2

2

Well as I see your are using the Git Repo, you can do this in the below way

As a very first step you need to find whether which project/solution is modified.

You can find the solution from my answer here,where you can see I've used a simple powershell script to pull out the modified files, and enables the corresponding variables.

Sample Powershell script to pull-out the modified files

$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 "SubFolderA/*")
    {
      Write-Host "##vso[task.setvariable variable=MicroserviceAUpdated]True"
    }
}
Jayendran
  • 9,638
  • 8
  • 60
  • 103
1

you cant achieve that with condition. condition are for executing tasks inside build. you are looking for build triggers in yaml files:

trigger:
  branches:
    include:
      - master
  paths:
    include:
      - path\to\app\*

this build will only trigger when anything under `path\to\app\ folder was changed. that way you create a build per app and can isolate those builds to specific files changed.

https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#pipeline

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • I can't create build per app. This would break CT and CD pipeline – Abhishek Jan 19 '19 at 09:50
  • i dont know what is ct, but that leaves you with no options, you can examine current commit and see what files were changed and make decisions based on that – 4c74356b41 Jan 19 '19 at 10:48