GitLab-Task-Scheduler is a powerful tool designed to automate the creation and scheduling of issues in GitLab projects using CI/CD pipelines.
To interact with the GitLab API, you need a project access token. Follow the instructions here: GitLab Documentation: Project Access Token
- Token Name:
Task Scheduler
- Role: Guest
- Expiration Date: Set an appropriate expiration date for your token.
- Scope:
api
Copy the token: After creating the token, copy it for use in the next steps.
Next, configure the necessary CI/CD variables in your GitLab project:
- Navigate to your project's settings and add a new variable.
- Set up the variable as follows:
- Type: Variable (default)
- Key:
TASK_SCHEDULER_PROJECT_ACCESS_TOKEN
- Value:
<your_project_access_token>
- Visibility: False
- Masked: True
- Protected: False
- Expand variable: False
For detailed instructions, visit: GitLab Documentation: CI/CD Variables.
Create a .gitlab-ci.yml
file in the root directory of your repository with the following content:
schedule_issues:
image: deve1musa/gitlab-task-scheduler:latest
script: gitlabtaskscheduler
only:
- schedules
This configuration sets up the pipeline to run the task scheduler using the specified Docker image.
Create a markdown file for each scheduled task in the .gitlab/scheduled_templates/ directory. Here is an example:
---
title: "Daily reminder" # The issue title
cron_expression: "@daily" # The schedule using crontab syntax, such as "*/30 * * * *", or a predefined value of @annually, @yearly, @monthly, @weekly, or @daily. Check https://crontab.guru/ for help.
active: true # Set to true to enable this template, false to disable
---
This is a daily reminder template.
Each template specifies the title, cron expression, and active status for the scheduled issue.
Set up the scheduled pipeline to trigger the task scheduler. Ensure the interval pattern is shorter than the cron_expression in the template to ensure it triggers correctly. For more details, see: Scheduled pipelines | GitLab.
Happy scheduling! ⏲️
- Python interpreter
- rye
- Docker
- Visual Studio Code (VSCode)
- Clone the repository:
git clone https://github.com/yourusername/gitlab-task-scheduler.git
cd gitlab-task-scheduler
- Install dependencies:
rye sync
- Run the scheduler locally:
python -m gitlabtaskscheduler