仅构建解决方案中更改的项目 -Azure CI 管道 - YAML [英] Build only projects which are changed in a solution -Azure CI pipeline - YAML
问题描述
我在一个解决方案下有多个项目,
I have multiple projects under a solution,
ProjectA.csproj
projectB.csproj
projectC.csproj
我已经为此解决方案创建了一个 YAML CI 构建管道,其中包含来自主分支的触发器
I have created a YAML CI build pipeline for this solution with trigger from Master Branch
触发器:-大师"
每当 Master 签入上述任何项目时,它都会触发 CI 管道并为上述所有单个项目创建工件.
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.
问题 - 我能否仅使用同一个 YAML 文件为解决方案构建有更改的项目?
Question - can I only build projects which have changes using the same single YAML file for the solution?
推荐答案
问题 - 我只能使用相同的方式构建具有更改的项目吗?解决方案的单个 YAML 文件?
Question - can I only build projects which have changes using the same single YAML file for the solution?
是的,你可以.假设您有多个 jobs/steps
用于不同的项目,您可以使用 Conditions 以确定何时应该运行/跳过一些特定步骤.你可以看看这个例子:
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')
那么如果我们只在 ProjectA
文件夹中进行更改,那么只有那些 condition: eq(variables['RunProjectA'], 'True')
的步骤/任务会运行.您应该在 ProjectA
、ProjectB
和 ProjectC
的管道中有三个单独的构建任务,并为它们提供您的自定义条件,然后您只能构建有变化的项目...(来自 this issue 中的 Jayendran 的提示!)
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!)
希望它有效.
这篇关于仅构建解决方案中更改的项目 -Azure CI 管道 - YAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!