I am trying to deploy one of the stages based on an schedule. I have defined the cron job in the azure-pipelines.yml file.
I have 5 stages.
- Build
- Deployment to Test - Country A
- Deployment to Test - Country B
- I want both of those stages being deployed after approval on monday till thursday at night. It must not be recurring only after approval.
- Deployment to Prod - Country A
- Deployment to Prod - Country B The same for those two stages.
schedules:
- cron: '31 12 * 1-12 1-5'
displayName: WeekDays
branches:
include:
- AddStage
always: true
- cron: '13 20 * 1-12 5-6'
displayName: Weekend
branches:
include:
- releases/*
always: true
I set the condition for the country stages, but unfortunately I am not able to achieve what I want:
condition: eq(variables['Build.CronSchedule.DisplayName'], 'WeekDays')
Based on your description, I generated the sample pipeline below. It contained 5 stages with 4 stages including a
deploymentjob to run against 4 pipeline environments.I added the
Approvalschecks for each environment and different conditions for each stage.Please note that to have the schedule trigger work for a certain branch (

AddStage), we need to check the pipeline reference.ymlfile on that branch and make sure the branch name isincluded.When the pipeline is triggered by the cron schedule
Weekdays, the stages with the conditioneq(variables['Build.CronSchedule.DisplayName'], 'WeekDays')will ask for approvals to continue, while the two stages with the conditioneq(variables['Build.CronSchedule.DisplayName'], 'Weekend')will be skipped,By the way, pipeline environment supports Business hours checks as well, which you may consider to add into your environment checks.
If this is not your specific scenario, please share a simple structure of your YAML pipeline and additional details to help understand your requirements. Hope the information helps.