2019-02-19 19:33:55 -05:00
|
|
|
# Pipeline schedules
|
2017-05-18 06:55:29 -04:00
|
|
|
|
|
|
|
> **Notes**:
|
2019-03-20 09:45:15 -04:00
|
|
|
>
|
2019-04-01 19:15:46 -04:00
|
|
|
> - Introduced in GitLab 9.1 as [Trigger Schedule](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10533).
|
|
|
|
> - [Renamed to Pipeline Schedule](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10853) in GitLab 9.2.
|
2019-01-08 10:36:38 -05:00
|
|
|
> - Cron notation is parsed by [Fugit](https://github.com/floraison/fugit).
|
2017-05-18 06:55:29 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
Pipelines are normally run based on certain conditions being met. For example, when a branch is pushed to repository.
|
2017-05-18 06:55:29 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
Pipeline schedules can be used to also run [pipelines](../../../ci/pipelines.md) at specific intervals. For example:
|
2017-05-18 06:55:29 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
- Every month on the 22nd for a certain branch.
|
|
|
|
- Once every day.
|
2017-05-18 06:55:29 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
In addition to using the GitLab UI, pipeline schedules can be maintained using the
|
|
|
|
[Pipeline schedules API](../../../api/pipeline_schedules.md).
|
|
|
|
|
|
|
|
## Configuring pipeline schedules
|
|
|
|
|
|
|
|
To schedule a pipeline for project:
|
|
|
|
|
|
|
|
1. Navigate to the project's **CI / CD > Schedules** page.
|
|
|
|
1. Click the **New schedule** button.
|
|
|
|
1. Fill in the **Schedule a new pipeline** form.
|
|
|
|
1. Click the **Save pipeline schedule** button.
|
2017-05-18 06:55:29 -04:00
|
|
|
|
|
|
|
![New Schedule Form](img/pipeline_schedules_new_form.png)
|
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
NOTE: **Note:**
|
|
|
|
Pipelines execution [timing is dependent](#advanced-configuration) on Sidekiq's own schedule.
|
2017-05-18 06:55:29 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
### Using variables
|
2017-06-29 00:10:53 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12328) in GitLab 9.4.
|
2017-06-29 00:10:53 -04:00
|
|
|
|
|
|
|
You can pass any number of arbitrary variables and they will be available in
|
2019-04-01 19:15:46 -04:00
|
|
|
GitLab CI so that they can be used in your [`.gitlab-ci.yml` file](../../../ci/yaml/README.md).
|
2017-06-29 00:10:53 -04:00
|
|
|
|
|
|
|
![Scheduled pipeline variables](img/pipeline_schedule_variables.png)
|
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
### Using only and except
|
2017-06-12 03:16:38 -04:00
|
|
|
|
|
|
|
To configure that a job can be executed only when the pipeline has been
|
|
|
|
scheduled (or the opposite), you can use
|
2019-03-25 00:56:57 -04:00
|
|
|
[only and except](../../../ci/yaml/README.md#onlyexcept-basic) configuration keywords.
|
2017-06-12 03:16:38 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
For example:
|
|
|
|
|
|
|
|
```yaml
|
2017-06-12 03:16:38 -04:00
|
|
|
job:on-schedule:
|
|
|
|
only:
|
|
|
|
- schedules
|
|
|
|
script:
|
|
|
|
- make world
|
|
|
|
|
|
|
|
job:
|
|
|
|
except:
|
|
|
|
- schedules
|
|
|
|
script:
|
|
|
|
- make build
|
|
|
|
```
|
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
### Advanced configuration
|
|
|
|
|
|
|
|
The pipelines won't be executed exactly on schedule because schedules are handled by
|
|
|
|
Sidekiq, which runs according to its interval.
|
|
|
|
|
|
|
|
For example, only two pipelines will be created per day if:
|
2017-05-18 06:55:29 -04:00
|
|
|
|
2019-04-01 19:15:46 -04:00
|
|
|
- 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:
|
|
|
|
|
2019-04-26 05:23:28 -04:00
|
|
|
1. Edit the `gitlab_rails['pipeline_schedule_worker_cron']` value in your instance's `gitlab.rb` file.
|
2019-04-01 19:15:46 -04:00
|
|
|
1. [Restart GitLab](../../../administration/restart_gitlab.md).
|
|
|
|
|
|
|
|
For GitLab.com, refer to the [dedicated settings page](../../gitlab_com/index.md#cron-jobs).
|
|
|
|
|
|
|
|
## Working with scheduled pipelines
|
|
|
|
|
|
|
|
Once configured, GitLab supports many functions for working with scheduled pipelines.
|
|
|
|
|
|
|
|
### Running manually
|
|
|
|
|
|
|
|
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/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)
|
|
|
|
|
|
|
|
This will schedule a background job to run the pipeline schedule. A flash
|
|
|
|
message will provide a link to the CI/CD Pipeline index page.
|
|
|
|
|
|
|
|
NOTE: **Note:**
|
|
|
|
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.
|
2017-05-18 06:55:29 -04:00
|
|
|
The next time a pipeline is scheduled, your credentials will be used.
|
|
|
|
|
|
|
|
![Schedules list](img/pipeline_schedules_ownership.png)
|
|
|
|
|
2018-11-30 02:32:30 -05:00
|
|
|
NOTE: **Note:**
|
|
|
|
If the owner of a pipeline schedule doesn't have the ability to create pipelines
|
|
|
|
on the target branch, the schedule will stop creating new pipelines. This can
|
|
|
|
happen if, for example, the owner is blocked or removed from the project, or
|
|
|
|
the target branch or tag is protected. In this case, someone with sufficient
|
|
|
|
privileges must take ownership of the schedule.
|