仅构建在解决方案中更改的项目-Azure CI管道-YAML [英] Build only projects which are changed in a solution -Azure CI pipeline - YAML
问题描述
我在一个解决方案下有多个项目,
ProjectA.csproj
projectB.csproj
projectC .csproj
我已经使用Master Branch的触发器为此解决方案创建了YAML CI构建管道
触发:-主人
只要上述任何项目的主人签到,它都会触发
问题-我只能使用相同的单个YAML文件来构建具有更改的项目吗?
问题? p>
问题-我只能使用相同的
单个YAML文件来构建具有更改的项目吗?解决方案?
是的,您可以。假设您有多个职位/步骤
用于不同的项目,则可以使用条件来确定何时应运行/跳过一些特定步骤。您可以检查以下示例:
触发:
-主
池:
vmImage:'windows-latest'
步骤:
-任务:PowerShell @ 2
输入:
targetType:'inline'
脚本: |
$ 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这是$ name文件
if($ name -like ProjectA / *)
{
Write-Host ## vso [task.setvariable variable = RunProjectA] True
}
if( $ name -like ProjectB / *)
{
写主机 ## vso [task.setvariable variable = RunProjectB] True
}
if($ name-如 ProjectC / *)
{
写主机 ## vso [task.setvariable variable = RunProjectC] True
}
}
-脚本:echo更改ProjectA文件夹时运行此步骤。
displayName:'运行A'
条件:eq(variables ['RunProjectA'],'True')
-脚本:echo更改ProjectB文件夹后运行此步骤。
displayName:'运行B'
条件:eq(variables ['RunProjectB'],'True')
-脚本:echo更改ProjectC文件夹后运行此步骤。
displayName:'Run C'
条件:eq(variables ['RunProjectC'],'True')
然后,如果我们仅在 ProjectA
文件夹中进行更改,则只有那些具有条件的步骤/任务:eq(variables [' RunProjectA'],'True')
将运行。您应该在管道中为 ProjectA
, ProjectB
和 ProjectC 进行三个单独的构建任务。 code>,并为他们提供自定义条件,那么您只能构建有更改的项目...(来自
希望它能起作用。
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?
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.
这篇关于仅构建在解决方案中更改的项目-Azure CI管道-YAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!