How to stop azure dev ops yaml validation build from running for each branch?

て烟熏妆下的殇ゞ 提交于 2021-02-05 09:44:39

问题


We are using azure dev ops for CICD and validating PR's.

Yesterday I decided to start making yaml files for validation builds.

I created the pipeline. I set the branch policy for 'development' fine and the validation build ran okay.

However, something I see is that each time ANY branch gets a change to the files of the directory I've set the validation build for a build triggers.

So, let's say I've made a yaml pipeline(CI only) for project Main(src/Main) and i've set a branch policy on branch 'development' to trigger a validation build whenever there is a change to that Main folder(src/Main/*) with the Main.sln inside and it has been PR's from branch(i.e. feature/Main/FirstPR). This works, but then if i merge 'development' into any branch which has not had the change to the main directory it will trigger that build. No other branch policy includes validation for Main apart from development even if it has not been PR-ed, but simply pushed to.

Here is an example of the yaml file. Any feedback would be appreciated.

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

pool:
  vmImage: 'windows-2019'
  demands: 
      - msbuild
      - visualstudio
      - vstest

variables:
  solution: 'src/Main/Main.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1
  inputs: 
    versionSpec: '5.0.0'

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '$(solution)'
    feedsToUse: 'select'
    vstsFeed: '5aaa76ac-3bqa-4567-usd9-btdse1c4c66a'
    restoreDirectory: '../../packages'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

回答1:


Set;

# A pipeline with no trigger
trigger: none

On your validation build pipeline. This will stop the build being run regardless of which branch / paths have been pushed.

The validation build pipeline will still respect the branch policies you've setup for PRs.

You can then have something like;

  paths:
    include:
      - 'src/ProjectA/*'
  branches:
    include:
      - development  

For your CI build pipelines which will trigger when there's a successful PR that affects ProjectA.



来源:https://stackoverflow.com/questions/60114828/how-to-stop-azure-dev-ops-yaml-validation-build-from-running-for-each-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!