debian-mirror-gitlab/doc/ci/pipelines/schedules.md

151 lines
5.3 KiB
Markdown
Raw Normal View History

2020-04-08 14:13:33 +05:30
---
2020-06-23 00:09:42 +05:30
stage: Verify
2021-09-04 01:27:46 +05:30
group: Pipeline Execution
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-04-08 14:13:33 +05:30
disqus_identifier: 'https://docs.gitlab.com/ee/user/project/pipelines/schedules.html'
type: reference, howto
---
2021-03-11 19:13:27 +05:30
# Pipeline schedules **(FREE)**
2020-04-08 14:13:33 +05:30
Pipelines are normally run based on certain conditions being met. For example, when a branch is pushed to repository.
Pipeline schedules can be used to also run [pipelines](index.md) at specific intervals. For example:
2021-12-11 22:18:48 +05:30
- Every month on the 22nd (cron example: `0 0 22 * *`) for a certain branch.
- Every month on the 2nd Monday (cron example: `0 0 * * 1#2`).
- Every other Sunday at 0900 hours (cron example: `0 9 * * sun%2`).
- Once every day (cron example: `0 0 * * *`).
Schedule timing is configured with cron notation, parsed by [Fugit](https://github.com/floraison/fugit).
2020-04-08 14:13:33 +05:30
In addition to using the GitLab UI, pipeline schedules can be maintained using the
[Pipeline schedules API](../../api/pipeline_schedules.md).
2020-05-24 23:13:21 +05:30
## Prerequisites
In order for a scheduled pipeline to be created successfully:
- The schedule owner must have [permissions](../../user/permissions.md) to merge into the target branch.
- The pipeline configuration must be valid.
Otherwise the pipeline is not created.
2020-04-08 14:13:33 +05:30
## Configuring pipeline schedules
To schedule a pipeline for project:
2021-04-17 20:07:23 +05:30
1. Navigate to the project's **CI/CD > Schedules** page.
2020-04-08 14:13:33 +05:30
1. Click the **New schedule** button.
1. Fill in the **Schedule a new pipeline** form.
1. Click the **Save pipeline schedule** button.
![New Schedule Form](img/pipeline_schedules_new_form.png)
2021-02-22 17:27:13 +05:30
NOTE:
2020-04-08 14:13:33 +05:30
Pipelines execution [timing is dependent](#advanced-configuration) on Sidekiq's own schedule.
In the **Schedules** index page you can see a list of the pipelines that are
scheduled to run. The next run is automatically calculated by the server GitLab
is installed on.
![Schedules list](img/pipeline_schedules_list.png)
### Using variables
2021-02-22 17:27:13 +05:30
You can pass any number of arbitrary variables. They are available in
2021-09-30 23:02:18 +05:30
GitLab CI/CD so that they can be used in your [`.gitlab-ci.yml` file](../../ci/yaml/index.md).
2020-04-08 14:13:33 +05:30
![Scheduled pipeline variables](img/pipeline_schedule_variables.png)
2021-09-04 01:27:46 +05:30
### Using `rules`
2020-04-08 14:13:33 +05:30
2021-02-22 17:27:13 +05:30
To configure a job to be executed only when the pipeline has been
2021-09-30 23:02:18 +05:30
scheduled, use the [`rules`](../yaml/index.md#rules) keyword.
2020-04-08 14:13:33 +05:30
2021-09-04 01:27:46 +05:30
In this example, `make world` runs in scheduled pipelines, and `make build`
runs in branch and tag pipelines:
2020-04-08 14:13:33 +05:30
```yaml
job:on-schedule:
2021-09-04 01:27:46 +05:30
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
2020-04-08 14:13:33 +05:30
script:
- make world
job:
2021-09-04 01:27:46 +05:30
rules:
2021-11-18 22:05:49 +05:30
- if: $CI_PIPELINE_SOURCE == "push"
2020-04-08 14:13:33 +05:30
script:
- make build
```
2021-03-11 19:13:27 +05:30
### Advanced configuration **(FREE SELF)**
2020-04-08 14:13:33 +05:30
2021-01-29 00:20:46 +05:30
The pipelines are not executed exactly on schedule because schedules are handled by
2020-04-08 14:13:33 +05:30
Sidekiq, which runs according to its interval.
2021-01-29 00:20:46 +05:30
For example, only two pipelines are created per day if:
2020-04-08 14:13:33 +05:30
- You set a schedule to create a pipeline every minute (`* * * * *`).
- The Sidekiq worker runs on 00:00 and 12:00 every day (`0 */12 * * *`).
To change the Sidekiq worker's frequency:
1. Edit the `gitlab_rails['pipeline_schedule_worker_cron']` value in your instance's `gitlab.rb` file.
1. [Reconfigure GitLab](../../administration/restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
For GitLab.com, refer to the [dedicated settings page](../../user/gitlab_com/index.md#gitlab-cicd).
## Working with scheduled pipelines
2021-02-22 17:27:13 +05:30
After configuration, GitLab supports many functions for working with scheduled pipelines.
2020-04-08 14:13:33 +05:30
### Running manually
> [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/15700) in GitLab 10.4.
To trigger a pipeline schedule manually, click the "Play" button:
![Play Pipeline Schedule](img/pipeline_schedule_play.png)
2021-01-29 00:20:46 +05:30
This schedules a background job to run the pipeline schedule. A flash
message provides a link to the CI/CD Pipeline index page.
2020-04-08 14:13:33 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2020-04-08 14:13:33 +05:30
To help avoid abuse, users are rate limited to triggering a pipeline once per
minute.
### Taking ownership
Pipelines are executed as a user, who owns a schedule. This influences what projects and other resources the pipeline has access to.
If a user does not own a pipeline, you can take ownership by clicking the **Take ownership** button.
2021-01-29 00:20:46 +05:30
The next time a pipeline is scheduled, your credentials are used.
2020-04-08 14:13:33 +05:30
![Schedules list](img/pipeline_schedules_ownership.png)
2021-02-22 17:27:13 +05:30
If the owner of a pipeline schedule cannot create
2021-01-29 00:20:46 +05:30
pipelines on the target branch, the schedule stops creating new
2020-04-08 14:13:33 +05:30
pipelines.
This can happen if, for example:
- The owner is blocked or removed from the project.
- The target branch or tag is protected.
In this case, someone with sufficient privileges must take ownership of the
schedule.
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X`.
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->