Ekaterina
Ekaterina

Reputation: 117

CD Yaml build is triggered for branch in filter, but builds default branch

I have 3 Yaml Pipelines:

CD is setup the following way:

YAML Settings

YAML Settings

Triggers Settings

![Triggers Settings

As you can see, I've tried different formats of the branches to branch filters. Even if I add non-wildcard filter, I still see the following behavior:

What should I change to deploy the artifact that was generated by CI2 build from services-release/* branch?

Upvotes: 0

Views: 436

Answers (1)

JukkaK
JukkaK

Reputation: 1175

Judging by the pictures, you are using yaml-pipelines but classic pipeline triggers. While this works for triggering the pipelines, you might want to consider implementing the triggers in yaml files for C1- and C2-pipelines.

https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers

As for the yaml-based CD pipeline, in order for the pipeline to trigger upon completion of CI2 and for it to download artifacts from the triggering run (instead of latest from the default pipeline), you should reference the CI2-pipeline as resource:

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers?view=azure-devops

So something like:

resources:
  pipelines:
  - pipeline: ci2_pipeline #this is used to reference this resource in CD pipeline
    source: CI2 #Rename this to match your build pipeline name
    trigger:
      branches:
      - services-release/*

For the artifacts, you want to ensure that you are using Pipeline Artifacts instead of classic build artifacts and use the Download Pipeline Artifacts -task in CD-pipeline (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/download-pipeline-artifact?view=azure-devops). So something like:

steps:
- download: none # Disable downloading default artifacts
- task: DownloadPipelineArtifact@2
  inputs:
    buildType: "specific"
    project: "$(resources.pipeline.ci2_pipeline.projectID)"
    definition: "$(resources.pipeline.ci2_pipeline.pipelineID)"
    preferTriggeringPipeline: true
        buildVersionToDownload: "latestFromBranch"
    branchName: "$(Build.SourceBranch)"
        targetPath: "$(Pipeline.Workspace)"

Upvotes: 0

Related Questions