Scheduled Tasks
About 367 wordsAbout 1 min
Introduction
Unlike regular pipelines, scheduled pipelines are triggered by timers. The scheduled task format uses POSIX cron
syntax. The timezone uses Asia/Shanghai
.
The example scheduled pipeline below will execute daily at 5:30 and 17:30 Asia/Shanghai
time. When executed, it will use the scheduled task owner as the pipeline trigger and run with the code from the main
branch. The owner is the user who pushed the scheduled task configuration (added or modified) to the repository. For example, if user A
pushes the example configuration to the main
branch, the owner is A
. Later if user B
modifies the configuration in the crontab: 30 5,17 * * *
event, the owner becomes B
.
When the scheduled task owner is removed from the repository, the scheduled pipeline will fail. The owner can be updated by modifying and pushing the scheduled task configuration again.
main:
# Regular push event pipeline
push:
- stages:
- name: test
script: echo 1
# Scheduled pipeline
"crontab: 30 5,17 * * *":
# Modifying content can reassociate the scheduled task trigger. Suggest modifying name for lower risk
- name: crontab-a
stages:
- name: test
script: echo 1
To provide more reliable service, we've set the minimum interval for scheduled tasks at 5 minutes. Scheduled tasks with intervals shorter than 5 minutes (e.g.: * * * * *
) cannot be added successfully.
Configuration Explanation
This section provides detailed explanations of each part of the scheduled pipeline configuration.
main:
"crontab: 30 5,17 * * *":
- stages:
- name: test
script: echo 1
main
Same as regular pipelines, you can specify an existing branch name in the repository. This determines which code the scheduled pipeline will use when executing. For example, if set to main
, the pipeline will use the code at HEAD
of the main
branch when executing.
To improve resource utilization, scheduled task branch names do not support
glob
expressions - only explicit branch names are allowed.
crontab: 30 5,17 * * *
Regular pipelines are typically triggered by operations like push
or pull_request
, which are one-time events.
But scheduled pipelines are triggered by timers, with the format crontab: ${CRON}
.
crontab:
is the fixed prefix for scheduled pipeline event names.${CRON}
is the actual execution time in standardPOSIX cron
syntax.