GitLab CI/CD: Architecting, Deploying, and Optimizing Pipelines

Architecture Core Concepts

Pipeline Schedules

Automate your pipeline runs by defining schedules that trigger at regular intervals—hourly, daily, weekly—or according to a custom cron expression. With pipeline schedules you can:

  • Execute deployments on a fixed timetable
  • Run maintenance or data sync scripts without manual intervention
  • Inject environment-specific variables for each run

Prerequisites

Before you begin:

  • A GitLab project with a .gitlab-ci.yml file
  • At least one job defined in your pipeline (e.g., deploy-job)
  • Maintainer or Owner permissions to manage CI/CD settings

1. Define the Deployment Job

In your .gitlab-ci.yml, create a job that references a CI/CD variable. This example echoes deployment steps using a custom variable, $DEPLOY_VARIABLE:

deploy-job:
  stage: deploy
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed to $DEPLOY_VARIABLE environment"

2. Configure a Pipeline Schedule

  1. In your GitLab project, navigate to CI/CD > Schedules.
  2. Click New schedule to open the scheduling form.

The image shows a GitLab interface for scheduling a new pipeline, with options to set the interval pattern, cron syntax, timezone, and target branch. The "Create pipeline schedule" button is visible at the bottom.

Select an Interval

Choose from presets (e.g., daily at 21:27) or specify a custom cron expression:

Note

Cron expressions must follow the format minute hour day-of-month month day-of-week. For a full reference, see the Cron Descriptor Guide.

0 0 1 1 *    # Runs once a year at midnight on January 1
ParameterDescriptionExample
IntervalPreset or custom cron0 0 1 1 *
TimezoneRegion-specific timezoneAsia/Kolkata (Mumbai)
Target branchBranch or tag for the schedulemain
CI/CD variablesKey-value pairs for this scheduleDEPLOY_VARIABLE=manual deployment

3. Add Variables and Create the Schedule

Specify any CI/CD variables needed by your job. For our deploy-job, define:

KeyValue
DEPLOY_VARIABLEmanual deployment

Warning

Ensure variable names match exactly what your .gitlab-ci.yml references. A typo will cause the job to fail.

Select Enable schedule and click Create pipeline schedule.

The image shows a GitLab interface for scheduling a new pipeline, with a dropdown menu for selecting a timezone and options for setting the target branch and variables.

4. View and Manage Schedules

All pipeline schedules are listed with details like next run time, cron expression, and target branch. Use the Play button to trigger any schedule on demand.

The image shows a GitLab interface displaying a pipeline schedule for a project, with options to manage and create new schedules.

5. Trigger and Verify the Scheduled Pipeline

  1. Click the Play icon to start a run immediately.
  2. Go to CI/CD > Pipelines and look for a pipeline tagged scheduled.
  3. Open the pipeline, then click the job (deploy-job) to review logs.

The image shows a GitLab CI/CD pipeline interface with a successful "deploy-job" under the "test" stage. The sidebar includes options like Project, Issues, Merge requests, and Pipelines.

Example job log:

$ echo "Deploying application..."
Deploying application...
$ echo "Application successfully deployed to $DEPLOY_VARIABLE environment"
Application successfully deployed to manual deployment environment

6. Edit or Remove Schedules

To adjust timing, update variables, or delete a schedule, return to CI/CD > Schedules, find the row, and click Edit or Delete as needed.

Watch Video

Watch video content

Previous
Use rules at Workflow Level