Hoghweed
Hoghweed

Reputation: 1948

Azure DevOps pipeline repository trigger doesn't fire

Context

I'm creating a CI/CD configuration for an application having this repository configuration (each repository in the same Organization and Project):

Within the repository r3 there are the solution's Azure DevOps Pipelines, each one of them has been configured for Manual & Scheduled trigger on develop branch:

  1. Frontend CI Pipeline p1
  2. Backend CI Pipeline p2
  3. Deployment Pipeline p3

The behavior I want is

  1. Git commit on r1 repo
  2. Pipeline p1 on repo r3 triggered (this will create artifacts, apply a tag and notify)
  3. Pipeline p3 triggered by p1 completion (this will deploy the artifacts)

Pipeline p1 looks like the following

trigger: none

resources:
  containers:
    - container: running-image
      image: ubuntu:latest
      options: "-v /usr/bin/sudo:/usr/bin/sudo -v /usr/lib/sudo/libsudo_util.so.0:/usr/lib/sudo/libsudo_util.so.0 -v /usr/lib/sudo/sudoers.so:/usr/lib/sudo/sudoers.so -v /etc/sudoers:/etc/sudoers"
  repositories:
    - repository: frontend
      name: r1
      type: git
      ref: develop
      trigger:
        branches:
          include:
            - develop
          exclude:
            - main

name: $(SourceBranchName)_$(date:yyyyMMdd)$(rev:.r) - Frontend App [CI]

variables:
  - name: imageName
    value: fronted-app
  - name: containerRegistryConnection
    value: apps-registry-connection

pool:
  vmImage: "ubuntu-latest"

stages:
  - stage: Build
    displayName: Build and push
    jobs:
      - job: JobBuild
        displayName: Build job
        container: running-image
        steps:
          - checkout: frontend
            displayName: Checkout Frontend repository
            path: fe
            persistCredentials: true

...

Pipeline p3 looks like the following

name: $(SourceBranchName)_$(date:yyyyMMdd)$(rev:.r) - App [CD]
trigger: none

resources:
  containers:
    - container: running-image
      image: ubuntu:latest
      options: "-v /usr/bin/sudo:/usr/bin/sudo -v /usr/lib/sudo/libsudo_util.so.0:/usr/lib/sudo/libsudo_util.so.0 -v /usr/lib/sudo/sudoers.so:/usr/lib/sudo/sudoers.so -v /etc/sudoers:/etc/sudoers"
  pipelines:
    - pipeline: app-fe-delivery
      source: "p1"
      trigger:
        stages:
          - Build
        branches:
          include:
            - develop


pool:
  vmImage: "ubuntu-latest"
stages:
  - stage: Delivery
    jobs:
      - job: JobDevelopment
        steps:
          - template: ../templates/template-setup.yaml # Template reference
            parameters:
              serviceDisplayName: ${{ variables.serviceDisplayName }}
              serviceName: ${{ variables.serviceName }}
...

Issue

Even if followed step by step all the rules exposed in the official documentation:

Remarks

Upvotes: 0

Views: 495

Answers (1)

DreadedFrost
DreadedFrost

Reputation: 2978

Couple possible solutions.

First off believe your issue is with:

trigger: none

This means the pipeline will only work manually. In the documentation you referenced :

Triggers are enabled by default on all the resources. However, you can choose to override/disable triggers for each resource.

The way this is configured all push triggers are disabled.

One possible way to achieve what you are attempting I believe is to remove the trigger:none from p1 and p3

If I read your question correctly you are trying to do a CI/CD build deployment on the repository. If so, may I suggest if the scenario is appropriate (i.e. a Build will always trigger a deployment) then combine these pipelines into one and put an if statement around the deployment stage similar to:

  - ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master')}}:

Also, if deploying to multiple environments this can be followed up with a loop indented in one line:

  - ${{ each environmentNames in parameters.environmentNames }}:

I noticed you are already using template so this would be just moving the template call up from the job to the stage and have it act as a wrapper. Feel free to provide feedback. If this answer isn't appropriate, I can update it accordingly.

Upvotes: 0

Related Questions