Auto Trigger Pipelines¶
You can configure triggers for your pipelines to automatically trigger them periodically. Click Edit Configuration when editing a pipeline to set up a build trigger.
Currently, the following types of triggers are supported:
- Code source trigger
- Webhook trigger
- Regular repository scan
- Scheduled trigger
Trigger Type | Description |
---|---|
Code Source Trigger | Choose the code repository integrated with your toolchain and configure corresponding trigger events. The pipeline will be triggered based on these events. Once configured, Workbench will automatically configure the Webhook address into the integrated code repository. |
Webhook Trigger | When the Webhook trigger is enabled, you will receive a Webhook address that you can use to trigger the pipeline through other systems. |
Regular Repository Scan | Checks the code repository for changes at a specified time. For example, entering H/15 * * * * means that the system will automatically check the code repository every 15 minutes for new changes. If there are new changes, the pipeline will be executed. |
Scheduled Trigger | Triggers the pipeline at a specified time. After enabling the scheduled trigger, you can directly select preset rules or choose to customize CRON expressions and enter custom trigger rules. |
Trigger Types¶
Code Source Trigger¶
Choose the code repository integrated with your toolchain (currently only integrated code repositories are supported), and configure corresponding trigger events. The pipeline will be triggered based on these events. Once configured, Workbench will automatically configure the Webhook address into the integrated code repository.
Prerequisites¶
- Integrate GitLab code repository into the current workspace
Trigger events¶
Branch Change
The pipeline is automatically triggered when the branch in the code repository matches the set branch and there are code changes in the current branch. Regular expressions are supported.
PR/MR
When enabled, the pipeline is automatically triggered when a new PR/MR is created, updated, or merged in the code repository.
Tag
When a Tag is created in the code repository, the pipeline is automatically triggered if it matches the set Tag rules. Regular expressions are supported.
Webhook Trigger¶
When the Webhook trigger is enabled, you will receive a Webhook address that you can use to trigger the pipeline through other systems.
For example, below are the steps to trigger a pipeline using a Gitlab repository's Webhook.
-
Go to Gitlab, select and enter a repository detail.
-
Click Settings -> Webhooks .
-
In the URL area, enter the address generated by enabling the Webhook. In the Trigger area, select the trigger events based on actual conditions.
-
Click Add webhook. A record will be generated in the Project Hooks area.
-
Click Test to check if the trigger is successful.
Regular Repository Scan¶
The system checks the code repository for changes at a specified time. For example, entering H/15 * * * * means that the system will automatically check the code repository every 15 minutes for new changes. If there are new changes, the pipeline will be executed.
Refer to the Trigger Rules Syntax section for a guide on trigger syntax.
Note
- For pipelines created by Jenkinsfile , the system will automatically check the code repository at the specified time after enabling this feature.
- For pipelines created through custom creation or template, after enabling this feature, you need to define the git clone step in the pipeline. Jenkins will check the filled git repository address. Please note that if the pipeline is triggered automatically after its first successful creation and enabling Regular Repository Scan, and the Jenkinsfile is empty at this time, the pipeline will fail to run. If we set the git clone step again without running the pipeline, the system will default to the failure of the pipeline and will not poll the repository. Therefore, we recommend that the Jenkinsfile should have data before enabling this feature.
Scheduled Trigger¶
Triggers the pipeline at a specified time. After enabling the scheduled trigger, you can directly select preset rules or choose to customize CRON expressions and enter custom trigger rules.
Refer to the trigger rules section for a guide on trigger syntax.
Trigger rules¶
Trigger rule syntax follows that of CRON (with a slight difference). Specifically, each line consists of 5 tab- or space-separated fields: MINUTE HOUR DOM MONTH DOW
Field | Description | Value Range |
---|---|---|
MINUTE | Minute | 0 ~ 59 |
HOUR | Hour | 0 ~ 23 |
DOM | Day of Month | 1 ~ 31 |
MONTH | Month | 1 ~ 12 |
DOW | Day of Week | 1 ~ 6 represent Monday to Saturday, 0 and 7 represent Sunday |
To specify multiple values for a field, you can use the following operators in order of priority:
Operator | Description |
---|---|
* | Represents all values within the value range |
M-N | Represents all values within a specified range |
M-N/X or */X | Triggers every X within a specified range or within the entire valid range |
A,B,...,Z | Represents multiple values |
In order for regularly scheduled tasks to create an even load on the system, the symbol H (for "hash") should be used whenever possible. For example, using 0 0 * * * for a dozen daily jobs will result in a large spike at midnight, possibly straining resources. In contrast, using H H * * * will still run each job once a day, but not all at once, which makes better use of limited resources.
H can be used with ranges. For example, H H(0-7) * * * means some time between 00:00 and 7:59.
Due to the different number of days in different months, when a short period such as /3 or H/3 appears in DOM , it will not be triggered at the end of most months. For example, */3 will trigger the task on the 1st, 4th, ..., 31st of each month. If there are 30 days in the next month, the last time the task is triggered is the 28th day.
Also, @yearly
, @annually
, @monthly
, @weekly
, @daily
, @midnight
, and @hourly
are convenient aliases. These use hashes for automatic matching. For example, @hourly
is the same as H * * * * and can represent any time within an hour. @midnight
represents a period of time between 0:00 and 2:59 every day.
Examples
Rule | Description |
---|---|
H/15 * * * * | Triggers every 15 minutes, for example, at 07, 22, 37, and 52 minutes past every hour |
H(0-29)/10 * * * * | Triggers every 10 minutes in the first half of every hour, for example, at 04, 14, and 24 minutes past every hour |
45 9-16/2 * * 1-5 | Triggers at 45 minutes past every 2 hours from 9:45 AM to 3:45 PM on every weekday |
H H(8-15)/2 * * 1-5 | Triggers at some point every 2 hours between 8 AM and 4 PM on every weekday, for example, at 9:38, 11:38, 13:38, and 15:38 |
H H 1,15 1-11 | Triggers once a day on the 1st and 15th of each month, except for December |