# Как реализовать запуск задач в .gitlab-ci.yml с различной периодичностью выполнения

1. Создать 2 планировщика (sheduler) 
    1. Меню: **Build** - **Pipeline Schedules** или **CI/CD** - **Schedules** (в зависимости от версии gitlab)  
        [![image.png](https://lavelin.ru/uploads/images/gallery/2024-04/scaled-1680-/image.png)](https://lavelin.ru/uploads/images/gallery/2024-04/image.png)
    2. Нажать на кнопку "**New schedule**"  
        [![image.png](https://lavelin.ru/uploads/images/gallery/2024-04/scaled-1680-/Skbimage.png)](https://lavelin.ru/uploads/images/gallery/2024-04/Skbimage.png)
    3. Указать в разделе перменных переменную для одного расписания  
        [![image.png](https://lavelin.ru/uploads/images/gallery/2024-04/scaled-1680-/4CIimage.png)](https://lavelin.ru/uploads/images/gallery/2024-04/4CIimage.png)
    4. Аналогично добавить второй планировщик и указать для него свою переменную
2. В файле .gitlab-ci.yml добавить правила выполнения для каждой переменной  
    [![image.png](https://lavelin.ru/uploads/images/gallery/2024-04/scaled-1680-/687image.png)](https://lavelin.ru/uploads/images/gallery/2024-04/687image.png)
3. Пример файла .gitlab-ci.yml
    
    ```yaml
    stages:
      - test
    
    .template_short:
      stage: test
      rules:
        - if: '$CI_PIPELINE_SOURCE == "schedule" && $interval == "short"'
      before_script:
        - echo "This is the before_script of the .template_short job"
    
    .template_long:
      stage: test
      rules:
        - if: '$CI_PIPELINE_SOURCE == "schedule" && $interval == "long"'
      before_script:
        - echo "This is the before_script of the .template_long job"
    
    test:daily:
      tags: 
        - my_tag
      extends: .template_short
      script:
        - echo "Run on $interval schedule"
    
    test:weekly:
      tags: 
        - my_tag
      extends: .template_long
      script:
        - echo "Run on $interval schedule"
    
    test:any:
      tags: 
        - my_tag
      script:
        - echo "Run on push and schedule"
    
    ```