Crontab Tasks

# Introduction

Unlike regular pipelines, crontab pipelines are triggered by a timer. The format for crontab tasks follows the POSIX cron syntax. The time zone used is Asia/Shanghai.

In the example below, the crontab pipeline will run every day at 5:30 and 17:30 in the Asia/Shanghai time zone. When executed, the pipeline will be triggered by the owner of the crontab task and will use the code from the main branch. The owner is the user who pushes the configuration for the crontab task (addition or modification) to the repository. For example, if user A pushes the configuration from the example to the main branch, then user A will be the owner. If user B later modifies the configuration in the crontab: 30 5,17 * * * event, then user B becomes the owner.

If the owner of a crontab task is removed from the repository, the crontab pipeline will fail. To update the owner, you can modify the configuration of the crontab task and push it again.

main:
  # Regular push event pipeline
  push:
    - stages:
        - name: test
          script: echo 1
  # Crontab pipeline
  "crontab: 30 5,17 * * *":
    # Modifying the content can reassign the owner of the crontab task.
    # It is recommended to modify the name to minimize the risk of issues.
    - name: crontab-a
      stages:
        - name: test
          script: echo 1

To provide a more reliable service, we have imposed a minimum time interval of 5 minutes for crontab tasks. crontab tasks with intervals less than 5 minutes (e.g., * * * * *) cannot be successfully added.

# Configuration Breakdown

This section will provide a detailed explanation of the configuration format and meaning for each part of the crontab pipeline.

main:
  "crontab: 30 5,17 * * *":
    - stages:
        - name: test
          script: echo 1

# main

Similar to regular pipelines, you can enter an existing branch name from your repository. This specifies the code that will be used when the scheduled pipeline is executed. For example, if you enter main, the pipeline will use the code from the HEAD of the main branch when it is executed.

To improve resource utilization, the branch names for scheduled task pipelines do not support glob expressions and must be explicit branch names.

# crontab: 30 5,17 * * *

Regular pipelines are usually triggered by specific events such as push or pull_request, which are one-time events.

However, crontab pipelines are triggered by a timer, and the format for this is crontab: ${CRON}.

  • crontab: is a fixed prefix for the crontab pipeline event name.
  • ${CRON} represents the actual execution time and follows the standard POSIX cron syntax.