.gitlab-ci.yml Basics

Advanced Configuration

< >

4. Advanced Configuration of .gitlab-ci.yml File

In this lesson, we will only mention some advanced configurations that you can use in your .gitlab-ci.yml file. These configurations can help you optimize your CI/CD pipeline and improve the efficiency of your workflows.

4.1 Environment Variables

You can use environment variables to manage sensitive information or configuration settings. [Developed more in the Intermediate Level Course]

variables: 
  LOG_LEVEL: "info"

4.2 Caching

Caching allows you to store dependencies or compiled outputs to speed up subsequent pipeline runs. So Cache is usually used when some of the following jobs need information that previous jobs have created.

cache:   
  paths:     
    - .cache/pip/

In this example, the .cache/pip/ directory is cached to speed up the installation of Python packages in subsequent pipeline runs. So that, the next time the pipeline runs, it will use the cached packages instead of downloading them again.

4.3 Dependencies

Dependencies allow you to define relationships between jobs, ensuring that a job only runs after its dependencies have successfully completed. This is useful when you have multiple jobs that need to be executed.

Dependencies

4.4 Using GitLab Runners

Specify the type of runner you want to use for your jobs. GitLab Runners are the agents that execute the jobs defined in your pipeline. They can be shared runners provided by GitLab or specific runners set up by you.

build_job:   
  stage: build   
  script:     
    - pip install -r requirements.txt     
    - python setup.py build   
  tags:     
    - docker # This tags defines that the runner you want to use is a Docker Runner

4.5 Only and Except Directives

The only and except directives allow you to control when a job should run based on specific conditions. This can be useful for running jobs only on specific branches or tags.

Only and Except

4.6 Pipeline Visualizations and Reports

GitLab provides visualizations and reports to monitor pipeline status, job outcomes, and performance metrics. These insights help teams identify bottlenecks, optimize workflows, and ensure continuous improvement in their CI/CD practices. You can make use of the Analyze > CI/CD analytics to gain insights into the CI pipeline.