-1

I had made the following YAML pipeline on Azure Pipelines, that will run two jobs, using a list of specific parameters, depending on the schedule that I had set.

Here's a tweaked (not the original) code snippet of what I had made. Though it hasn't been run by schedule yet, the original code does work when I run it manually.

#./azure-pipelines.yml

trigger: none

# Based on the name of the schedule, the assigned parameter will be called.
schedules:
  - cron: "0 17 * * Fri"
    displayName: Weekly Run
    branches:
      include:
      - main
    always: true
  - cron: "0 17 /15 * Fri"
    displayName: Bi-Weekly Run
    branches:
      include:
      - main
    always: true
    batch: true # Pipeline will run even when an older scheduled pipeline is running as well

pool: windows-latest

parameters:
  - name: weeklyList
    type: object
    default:
      - "apple"
      - "watermelon"
  - name: biWeeklyList
    type: object
    default:
      - "orange"
      - "melon"

jobs:
- job : Weekly_Run
  ${{ if ne(variables['Build.Reason'], 'Manual') }}:
    condition: eq(variables['Build.CronSchedule.DisplayName'], 'Weekly Run')
  steps:
  - ${{ each fruit in parameters.weeklyList }}:
    - script: echo ${{ fruit }}

- job : Bi_Weekly_Run
  ${{ if ne(variables['Build.Reason'], 'Manual') }}:
    condition: eq(variables['Build.CronSchedule.DisplayName'], 'Bi-Weekly Run')
  steps:
  - ${{ each fruit in parameters.biWeeklyList}}:
    - script: echo ${{ fruit }}

For monitoring sake, I'd like to have two pipelines, one will have only a list of weekly runs and and the other is a list of biweekly runs. For example's sake, let's call them Pipeline-Weekly and Pipeline-BiWeekly.

Is it possible to have Pipeline-Weekly and Pipeline-BiWeekly referencing to the same YAML file, i.e. azure-pipelines.yml, but show the jobs they're intended for monitoring?

How do I set that? It seemed like the answer by Levi Lu-MSFT in https://stackoverflow.com/a/64656297/6681261 is pointing in this direction, but it also looks to me that that's a separate YAML (which I'm trying to avoid, unless it's necessary), but it "overrides" the parameter.

Adji_PA
  • 74
  • 8
  • If you want two pipelines, create two pipelines. You can extract common jobs and stages to a template and reference them accordingly. – Daniel Mann Aug 17 '23 at 14:56
  • So what you're saying is, extract as much as you can to a template to be referenced, create two yaml data, one for weekly, one for biweekly, and finally create two pipelines on Azure Pipelines that reference to each respectively. So there's no way to use the same file (same template yamls, sure, but not the same yaml pipeline file) to display two different monitoring information? – Adji_PA Aug 18 '23 at 09:51
  • No. Triggers/schedules can't be conditional. – Daniel Mann Aug 18 '23 at 16:15

0 Answers0