GitLab CI/CD
Overview
GitLab CI/CD is a powerful, built-in continuous integration and continuous delivery (CI/CD) solution that enables automated software development workflows. This outline covers key aspects of GitLab CI/CD, including its core features and capabilities:
Continuous Integration:
- Pipelines: Defines the CI/CD workflow, consisting of multiple jobs that are executed in a specific order.
- Jobs: Represent individual tasks within a pipeline, such as building, testing, and deploying code.
- Runners: Execute the jobs defined in a pipeline, running on various platforms and operating systems.
Continuous Delivery:
- Artifacts: Allow sharing output from jobs, such as compiled binaries, test reports, or documentation, across pipelines or projects.
- Deployment: Streamlines the deployment process, enabling the automatic delivery of application changes to different environments (development, staging, production).
Pipelines
Defining Pipelines
Pipelines are defined using a .gitlab-ci.yml
file located in the root of your repository. This file describes the jobs, stages, and dependencies that comprise your CI/CD workflow.
Example:
stages:
- build
- test
- deploy
build:
stage: build
script:
- echo "Building application..."
- make build
test:
stage: test
script:
- echo "Running tests..."
- make test
deploy:
stage: deploy
script:
- echo "Deploying to staging..."
- make deploy staging
Source: https://docs.gitlab.com/ee/ci/yaml/README.html
Pipeline Stages
Stages define logical groups of jobs that are executed in order. Jobs within the same stage can run in parallel, while jobs in different stages run sequentially.
Example:
stages:
- build
- test
- deploy
Source: https://docs.gitlab.com/ee/ci/yaml/stages.html
Pipeline Jobs
Jobs are individual tasks within a pipeline. Each job can have its own configuration, including scripts, dependencies, and artifacts.
Example:
build:
stage: build
script:
- echo "Building application..."
- make build
Source: https://docs.gitlab.com/ee/ci/yaml/jobs.html
Runners
Runners are the execution environments for your CI/CD jobs. They can be hosted on your own infrastructure, or you can use GitLab’s shared runners.
Example:
stages:
- build
build:
stage: build
image: alpine:latest
script:
- echo "Building application..."
- make build
Source: https://docs.gitlab.com/ee/ci/runners/README.html
Artifacts
Artifacts are files produced by CI/CD jobs, such as compiled binaries, test reports, or documentation. They can be shared across pipelines and projects.
Example:
build:
stage: build
script:
- echo "Building application..."
- make build
artifacts:
paths:
- build/
Source: https://docs.gitlab.com/ee/ci/yaml/artifacts.html
Deployments
GitLab CI/CD simplifies the deployment process, enabling automatic delivery of application changes to different environments. You can use the built-in features or integrate with external deployment tools.
Example:
deploy:
stage: deploy
script:
- echo "Deploying to staging..."
- make deploy staging
environment: staging