You can do like below
- Create variables based on your microservices with the values “False”
E.g,MicroserviceAUpdated
= “False”,MicroserviceBUpdated
= “False” etc.,
- Add a Powershell script task at the begin of your build definition.
The powershell script will do the following:
Get the changeset/commit in the build to check which files are changed.
- Update the
MicroserviceAUpdated
variable to “true” if only any
files are changed underSubFolderA
. - Update the
MicroserviceBUpdated
variable to “true” if only any
files are changed underSubFolderA
.
So on….
- Create separate build task for each microservice, configure the build tasks to run with custom conditions like below
For MicroserviceA build Task
“Custom conditions”:
and(succeeded(), eq(variables['MicroserviceAUpdated'], 'True'))
For MicroserviceB build Task
“Custom conditions”:
and(succeeded(), eq(variables['MicroserviceBUpdated'], 'True'))
So on…
This way MicoserviceTask will be skipped if the value of the variable is False
For Step 2
$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"
}
}