0

I have a very simple pipeline that has a 1 stage and 1 job that prints Hello World.

I would like the stage to be triggered based only on the schedule (not when I push).

schedules:
- cron: "*/5 * * * *"
  displayName: Run every 5 Mins
  branches:
    include:
    - main
  always: true  

stages:
- stage: BatchRun
  displayName: Batch Run
  condition: and(always(), eq(variables['Build.Reason'], 'Schedule'))
  jobs:
  - job: Echo
    steps:
    - script: 'Hello World'

Currently, there are 2 problems

  1. The stage is triggered when I push.
  2. the job is skipped with a message The job was skipped. I have no information as to why.

I have tried with different condition eq(variables['Build.Reason'], 'Schedule')

I have also tried having another stage before the stage with the condition.

- stage: A
  jobs:
  - job: A1
    steps:
      - script: echo Hello Stage A!

I have looked at Microsoft's documentation.

Vergil C.
  • 1,046
  • 2
  • 15
  • 28
  • I am guessing the skipping is due to ADO not recognizing the run as a schedule since it is going off of every push it sounds like. Is the branch you are pushing to master or a different one? – DreadedFrost Jun 08 '21 at 12:55
  • @DreadFrost is on master, is there any way to check (logs) or another way if the job is recognized as scheduled? – Vergil C. Jun 08 '21 at 13:02
  • 1
    Your pipeline is looking for `main` if you want to check after the pipeline has been ran click the hamburger menue and download logs. There is an azure-pipelines.expanded.yaml file – DreadedFrost Jun 08 '21 at 13:04
  • I'm facepalming myself, the copy and paste side effect, just corrected it and my second stage now is running, will wait and see if it will run again in 5 mins. Also will check what happens when I have another commit, thanks. Will update here later. – Vergil C. Jun 08 '21 at 13:08
  • I've had this same issue with my pipelines after the default was switched from `master` to `main` :) – DreadedFrost Jun 08 '21 at 13:15

2 Answers2

1

To make the pipeline not trigger with push, add trigger: none. More information here.

As for the job skipped, you seem to have found the answer, but for reference, such things can happen when GUI settings override YAML, something to watch out for.

psfinaki
  • 1,814
  • 15
  • 29
0

The solution was

trigger: none

schedules:
- cron: "*/5 * * * *"
  displayName: Run every 5 Mins
  branches:
    include:
    - main
  always: true  

stages:
- stage: BatchRun
  displayName: Batch Run
  jobs:
  - job: Echo
    steps:
    - script: 'echo "Hello World"'
  1. To add trigger: none as @psfinaki mentioned so the job does not run by on commit
  2. Since in this example I have only one stage, I removed the condition alltogether. If there are multiple stages, those cane be targeted then with conditions.
Vergil C.
  • 1,046
  • 2
  • 15
  • 28