CI Azure 管道触发器
CI Triggers on Pipelines in Azure
每当有人提交或推送某些内容到我们存储库的分支时,管道就会触发,我在遵循 Microsoft Doc 时遇到了真正的问题:https://docs.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
部分中有任何内容,则仅推送到这些分支会触发构建。如果您同时指定 include
和 exclude
部分,那么它将尝试从 include
集中排除一些子集 - 就像文档中的示例一样:
# specific branch build
trigger:
branches:
include:
- master
- releases/*
exclude:
- releases/old*
如果管道仍然被推送到其他分支触发,那么一定是其他东西触发了它。
正如@yan-sklyraneko 在此 中提到的,您的触发器配置应该像
一样简单
trigger:
- master
但是,您的 YAML 文件中的触发器可以在 GUI 中被覆盖。导航到您的管道并单击 Edit
,然后单击如下所示的省略号和 select Triggers
在该屏幕上检查 Override the YAML continuous integration trigger from here
框是否未选中
我最终解决了这个问题,我最终走上了通过 Azure Dev Ops 门户进行管理的路线。
似乎如果您尝试使用 YAML 来管理它是行不通的,但如果您按照答案 2 中所述通过 Web 界面进行操作,则行为符合预期。我认为 Microsoft YAML 部分为此已损坏,但我已经与 Microsoft 一起解决了三个问题,我不想添加另一个问题来关注和标记。
每当有人提交或推送某些内容到我们存储库的分支时,管道就会触发,我在遵循 Microsoft Doc 时遇到了真正的问题:https://docs.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
部分中有任何内容,则仅推送到这些分支会触发构建。如果您同时指定 include
和 exclude
部分,那么它将尝试从 include
集中排除一些子集 - 就像文档中的示例一样:
# specific branch build
trigger:
branches:
include:
- master
- releases/*
exclude:
- releases/old*
如果管道仍然被推送到其他分支触发,那么一定是其他东西触发了它。
正如@yan-sklyraneko 在此
trigger:
- master
但是,您的 YAML 文件中的触发器可以在 GUI 中被覆盖。导航到您的管道并单击 Edit
,然后单击如下所示的省略号和 select Triggers
在该屏幕上检查 Override the YAML continuous integration trigger from here
框是否未选中
我最终解决了这个问题,我最终走上了通过 Azure Dev Ops 门户进行管理的路线。
似乎如果您尝试使用 YAML 来管理它是行不通的,但如果您按照答案 2 中所述通过 Web 界面进行操作,则行为符合预期。我认为 Microsoft YAML 部分为此已损坏,但我已经与 Microsoft 一起解决了三个问题,我不想添加另一个问题来关注和标记。