简体   繁体   中英

CI Triggers on Pipelines in Azure

Im having real issues with a pipeline everytime someone commits or pushes something to a branch on our repo, the pipeline triggers, in following the Microsoft Doc: https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers

Putting in Exclude features on every branch that we have the pipeline will still run when someone does a commit to a local branch even if I have wild carded the branch.

Has anyone been able to get this to work, that the pipeline should only run when there is a commit to Master only and nothing else.

Here is my Code:

 trigger: branches: include: - master exclude: - CICV/* - An/* - Prod/* - Test/* - Dev/* - dev/* - IN/* - id/* - St/* - tr/* pool: vmImage: 'windows-latest' demands: npm variables: System.Debug: false azureSubscription: 'RunPipelinesInProd' RG: 'VALUE' Location: UK South containername: 'private' appconnectionname: 'RunPipelinesInProd' jobs: - job: job1 displayName: Create And Publish Artifact pool: vmImage: vs2017-win2016 steps: - task: UseDotNet@2 displayName: Use.Net Core 3.1.x SDK inputs: packageType: 'sdk' version: '3.1.x' - task: DotNetCoreCLI@2 displayName: dotnet restore inputs: command: restore projects: 'Website.csproj' - task: Npm@1 displayName: 'npm install' inputs: workingDir: ClientApp verbose: false - task: Npm@1 displayName: 'npm run build' inputs: command: 'custom' workingDir: ClientApp customCommand: 'build' - task: DotNetCoreCLI@2 displayName: dotnet build inputs: projects: 'Website.csproj' arguments: '--configuration Release' - task: DotNetCoreCLI@2 displayName: dotnet Test inputs: command: test projects: 'UnitTests/UnitTests.csproj' arguments: '--configuration Release' - task: DotNetCoreCLI@2 displayName: dotnet publish inputs: command: publish projects: 'Website.csproj' arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)' zipAfterPublish: true modifyOutputPath: false - task: PublishPipelineArtifact@1 displayName: Publish Pipeline Artifact inputs: targetPath: '$(Build.ArtifactStagingDirectory)' artifact: 'Website' publishLocation: 'pipeline' - job: job2 displayName: Create Web App dependsOn: job1 steps: # Download Artifact File - download: none - task: DownloadPipelineArtifact@2 displayName: 'Download Build Artifacts' inputs: patterns: '**/*.zip' path: '$(Build.ArtifactStagingDirectory)' # deploy to Azure Web App - task: AzureWebApp@1 displayName: 'Azure Web App Deploy: nsclassroom-dgyn27h2dfoyo' inputs: package: $(Build.ArtifactStagingDirectory)/**/*.zip azureSubscription: $(azureSubscription) ConnectedServiceName: $(appconnectionname) appName: 'VALUE' ResourceGroupName: $(RG)

You don't need a complex trigger like the one you outlined to trigger the pipeline on pushes to master. The following simple trigger configuration should work:

trigger:
  - master

If there's anything in the include section, then only pushes to these branches trigger the build. If you specify both include and exclude sections, then it will try to exclude some subset from the include set - just like in the sample from the docs:

# specific branch build
trigger:
  branches:
    include:
    - master
    - releases/*
    exclude:
    - releases/old*

If the pipeline is still triggered by the push to some other branch, then it must be something else that triggers it.

As mentioned by @yan-sklyraneko in this answer your trigger configuration should be as simple as

trigger:
 - master

However the trigger in your YAML file can be overridden in the GUI. Navigate to your pipeline and click Edit then click the ellipses as shown below and select Triggers

在此处输入图像描述

On that screen check that the Override the YAML continuous integration trigger from here box is unticked

在此处输入图像描述

I solved this in the end, I ended up down the route of managing through the Azure Dev Ops Portal.

It seems that if you try to use YAML to manage this it just doesn't work, but if you do it through the web interface as outlined in Answer 2, then the behaviour is as expected. I think that the Microsoft YAML part is broken for this but I already have three issues open with Microsoft I don't wish to add another one to follow and tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM