简体   繁体   English

Azure 中管道上的 CI 触发器

[英]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每当有人在我们的仓库中提交或推送某些内容到我们的 repo 上的分支时,管道都会触发真正的问题,遵循 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.有没有人能够让这个工作,管道应该只在提交到 Master 而没有其他的时候运行。

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.您不需要像您概述的那样复杂的触发器来触发推送到 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.如果include部分中有任何内容,那么只有推送到这些分支才会触发构建。 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:如果您同时指定includeexclude部分,那么它将尝试从include集中排除一些子集 - 就像在文档中的示例中一样:

# 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正如@yan-sklyraneko 在这个答案中提到的那样,您的触发器配置应该很简单

trigger:
 - master

However the trigger in your YAML file can be overridden in the GUI.但是,可以在 GUI 中覆盖 YAML 文件中的触发器。 Navigate to your pipeline and click Edit then click the ellipses as shown below and select Triggers导航到您的管道并单击Edit ,然后单击省略号,如下所示和 select Triggers

在此处输入图像描述

On that screen check that the Override the YAML continuous integration trigger from here box is unticked在该屏幕上检查Override the YAML continuous integration trigger from here框是否未选中

在此处输入图像描述

I solved this in the end, I ended up down the route of managing through the Azure Dev Ops Portal.我最终解决了这个问题,我最终通过 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.似乎如果您尝试使用 YAML 来管理它,它只是不起作用,但如果您通过答案 2 中概述的 web 接口执行此操作,则行为与预期一致。 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.我认为 Microsoft YAML 部分因此而损坏,但我已经与 Microsoft 提出了三个问题,我不希望添加另一个问题来关注和标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用或不使用触发器为 Azure 数据工厂创建 CI 和 CD 管道 - Creating CI and CD pipelines for Azure data factory with or without triggers Azure 管道为每个拉取请求触发 2 个作业 - Azure pipelines triggers 2 jobs per pull request azure-pipelines.yml 中的多个单独触发器 - Multiple separate triggers in azure-pipelines.yml 使用 Azure DevOps CI/CD 管道自动部署 ADF 管道 - Automated Deployment of ADF Pipelines using Azure DevOps CI/CD Pipelines 如何在 Azure 管道中组合 Git 分支和标记触发器 - How to combine Git branch and tag triggers in Azure Pipelines Azure管道秘密变量不适用于PR触发器 - Azure pipelines Secret Variables don't work on PR triggers 如何在Azure Pipelines for CI / CD中使用较新版本的Maven进行构建 - How to use newer versions of Maven for builds in Azure Pipelines for CI/CD npm error missing script: build (Set up CI with Azure Pipelines) - npm error missing script: build (Set up CI with Azure Pipelines) 如何使用 azure tfs 在 CI/CD 管道中配置应用程序设置 - How to configure app settings in CI/CD pipelines using azure tfs Azure DevOps CI/CD 未在活动中部署我的管道触发器 state - Azure DevOps CI/CD not deploying my pipeline triggers in an Active state
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM