azure - Azure 管道上的 CI 触发器

标签 azure azure-devops continuous-integration yaml azure-pipelines

每当有人向我们的存储库上的分支提交或推送某些内容时,管道就会触发,按照 Microsoft 文档:https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers,我就会遇到管道的实际问题:

当有人提交到本地分支时,即使我对分支进行了通配符,在我们拥有管道的每个分支上放入排除功能仍然会运行。

有没有人能够让它发挥作用,管道应该仅在仅提交给 Master 而没有其他内容时运行。

这是我的代码:

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)

 

最佳答案

您不需要像您概述的那样复杂的触发器来触发推送到 master 的管道。以下简单的触发器配置应该可以工作:

trigger:
  - master

如果 include 部分中有任何内容,则只有推送到这些分支才会触发构建。如果您同时指定 includeexclude 部分,那么它将尝试从 include 集中排除某些子集 - 就像示例中的那样文档:

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

如果管道仍然由推送到其他分支而触发,那么一定是其他东西触发了它。

关于azure - Azure 管道上的 CI 触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67176233/

相关文章:

wcf - 我得到 For TransferMode.Buffered, MaxReceivedMessageSize 和 MaxBufferSize 必须是相同的值

c# - 将文件从 Azure 存储 blob 移动到 Ftp 服务器

azure - Next.js 中的公共(public)环境变量在 Azure 静态 Web 应用程序中不起作用

visual-studio - VSTS:如何在Visual Studio构建步骤为多个项目中处理FileSystem WebPublishMethod

Android-Jenkins : failed to find Build Tools revision 17. 0.0 在 Jenkins 构建服务器上

Azure Kubernetes 子网和网络安全组

azure - 在带有IdentityServer4认证/http错误的Azure Web应用程序容器上部署.net Core 3 Linux容器

powershell - 表示 Azure DevOps 管道中的列表变量,用于 PowerShell

maven - 无法获得某些功能文件标签以通过TeamCity运行

svn - 使用持续集成构建标签