Junior — Middle
How can you automate the execution of recurring tasks in GitLab CI/CD?
sobes.tech AI
Answer from AI
In GitLab CI/CD, to automate the execution of recurring tasks, you can use:
-
Cron-like schedules (Schedules) — allow you to set up periodic pipeline runs according to a schedule (for example, daily, weekly).
To do this, a new schedule with a cron expression and branch is created in the GitLab interface under CI/CD -> Schedules.
-
Parameters in
.gitlab-ci.yml— you can define a job that will run on a schedule.
Example of schedule configuration in .gitlab-ci.yml:
stages:
- cleanup
cleanup_job:
stage: cleanup
script:
- echo "Performing cleanup"
only:
- schedules
Then, a schedule is created in the GitLab interface that will automatically run this job at the specified time.
Thus, the combination of schedules and settings in .gitlab-ci.yml allows automating recurring tasks.