[英]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:如果您同时指定
include
和exclude
部分,那么它将尝试从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.