0
votes

Trying to piece together documentation (https://docs.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers) on trigger/resources to create a set of pipelines that will have a build pipeline triggered by a commit and when that pipeline completes a deployment pipeline consumes the artifacts and deploys them. The reason for having a separate build and deployment pipeline is for batching commits for PRs landing in the mainline (read-as: master)

While the below pipeline files work when a build is manually triggered when a commit is made to the repo both pipelines are started. That isn't what is wanted. If the triggers are removed from the deploy pipeline then the pipeline to pipeline triggers are working.

We want:

  1. Repo commit
  2. Build pipeline starts
  3. Build pipeline publishes artifacts
  4. Deploy pipeline starts
  5. Deploy pipeline consumes artifacts
  6. Deploy pipeline deploys artifacts

build-pipeline.yml

name: $(date:yyyy).$(date:MM).$(date:dd)$(rev:.r)

trigger:
- master
- feature/*

pool:
vmImage: 'ubuntu-latest'

variables:
artifactsName: "artifacts"

steps:
- task: PowerShell@2
inputs:
    targetType: 'inline'
    script: |
    Write-Host "Executing Build"
    Write-Host "Creating Artifacts"
    New-Item -Type Directory -Path $(artifactsName)
    $artifactPath = Join-Path -Path $(artifactsName) -ChildPath "$(Build.BuildNumber).txt"
    Set-Content -Path $artifactPath -Value "$(Get-Date)"
    pwsh: true

- task: PublishPipelineArtifact@1
inputs:
    targetPath: $(artifactsName)
    artifactName: buildartifacts

deploy-pipeline.yml

resources:
pipelines:
- pipeline: buildpipeline
    source: -splitpipeline-build
    trigger:
    branches:
        include:
        - master
        - feature/*

pool:
vmImage: 'ubuntu-latest'

steps:
- script: echo Deploy Step 
displayName: 'Deploy'
1

1 Answers

0
votes

You have to add trigger: none to your deploy-pipeline.yml if you want to avoid run after commit. There is a chance also that pr: none is needed because pipeline may run when you create pull request. To sum up this works as you need:

build-pipeline.yml

name: $(date:yyyy).$(date:MM).$(date:dd)$(rev:.r)

trigger:
- master
- feature/*

pool:
  vmImage: 'ubuntu-latest'

variables:
  artifactsName: "artifacts"

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Write-Host "Executing Build"
      Write-Host "Creating Super Artifacts"
      New-Item -Type Directory -Path $(artifactsName)
      $artifactPath = Join-Path -Path $(artifactsName) -ChildPath "$(Build.BuildNumber).txt"
      Set-Content -Path $artifactPath -Value "$(Get-Date)"
    pwsh: true

- task: PublishPipelineArtifact@1
  inputs:
    targetPath: $(artifactsName)
    artifactName: buildartifacts

deploy-pipeline.yml

resources:
  pipelines:
  - pipeline: buildpipeline
    source: stackoverflow\kmadof.dm-so-15-a
    trigger:
      branches:
        include:
        - master
        - feature/*

trigger: none

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: echo Deploy Step 
  displayName: 'Deploy'

Please check the doc for more details:

When you specify both CI triggers and pipeline triggers, you can expect new runs to be started every time (a) an update is made to the repository and (b) a run of the upstream pipeline is completed. Consider an example of a pipeline B that depends on A. Let us also assume that both of these pipelines use the same repository for the source code, and that both of them also have CI triggers configured. When you push an update to the repository, then:

  • A new run of A is started.
  • At the same time, a new run of B is started. This run will consume the previously produced artifacts from A.
  • As A completes, it will trigger another run of B.

To prevent triggering two runs of B in this example, you must remove its CI trigger or pipeline trigger.