Build only projects which are changed in a solution -Azure CI pipeline - YAML

后端 未结 2 1846
梦谈多话
梦谈多话 2021-01-29 07:45

I have multiple projects under a solution,

ProjectA.csproj
projectB.csproj
projectC.csproj

I have created a YAML CI build pipeline for this sol

相关标签:
2条回答
  • 2021-01-29 08:17

    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.

    0 讨论(0)
  • 2021-01-29 08:27

    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
    
    0 讨论(0)
提交回复
热议问题