Reputation: 123
I have multiple projects under a solution,
ProjectA.csproj
projectB.csproj
projectC.csproj
I have created a YAML CI build pipeline for this solution with trigger from Master Branch
"trigger: - Master"
Whenever a check-in happens to Master for any of the project above, it triggers the CI pipeline and create artifacts for all the above individual projects.
Question - can I only build projects which have changes using the same single YAML file for the solution?
Upvotes: 4
Views: 3694
Reputation: 31
Add the allowPackageConflicts input. It allows publish of just a single project in the solution. Only projects with an updated version number is published.
# publish to artifacts:
- task: NuGetCommand@2
inputs:
command: 'push'
allowPackageConflicts: true
Upvotes: 1
Reputation: 28176
Question - can I only build projects which have changes using the same single YAML file for the solution?
Yes, you can. Assuming you have multiple jobs/steps
for different projects, you can use Conditions to determine when it should run/skip some specific steps. You can check this example:
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$files=$(git diff HEAD HEAD~ --name-only)
$temp=$files -split ' '
$count=$temp.Length
For ($i=0; $i -lt $temp.Length; $i++)
{
$name=$temp[$i]
echo "this is $name file"
if ($name -like "ProjectA/*")
{
Write-Host "##vso[task.setvariable variable=RunProjectA]True"
}
if ($name -like "ProjectB/*")
{
Write-Host "##vso[task.setvariable variable=RunProjectB]True"
}
if ($name -like "ProjectC/*")
{
Write-Host "##vso[task.setvariable variable=RunProjectC]True"
}
}
- script: echo "Run this step when ProjectA folder is changed."
displayName: 'Run A'
condition: eq(variables['RunProjectA'], 'True')
- script: echo "Run this step when ProjectB folder is changed."
displayName: 'Run B'
condition: eq(variables['RunProjectB'], 'True')
- script: echo "Run this step when ProjectC folder is changed."
displayName: 'Run C'
condition: eq(variables['RunProjectC'], 'True')
Then if we only have changes in ProjectA
folder, only those steps/tasks with condition: eq(variables['RunProjectA'], 'True')
will run. You should have three separate build tasks in your pipeline for ProjectA
, ProjectB
and ProjectC
, and give them your custom condition, then you can only build projects which have changes... (Hint from Jayendran in this issue!)
Hope it works.
Upvotes: 6