gitlab-ci-patterns
Build GitLab CI/CD pipelines with multi-stage workflows, caching, and distributed runners for scalable automation. Use when implementing GitLab CI/CD, optimizing pipeline performance, or setting up automated testing and deployment.
Author
Category
Development ToolsInstall
Hot:2
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-gitlab-ci-patterns&locale=en&source=copy
GitLab CI Patterns - GitLab CI/CD Pipeline Templates and Best Practices
Skills Overview
GitLab CI Patterns provides a complete set of templates for designing GitLab CI/CD pipelines, covering common scenarios such as multi-stage workflows, caching strategies, Docker builds, Kubernetes deployments, and security scanning.
Suitable Use Cases
1. Automate GitLab CI/CD Workflows
Quickly set up CI/CD pipelines for new projects, including code building, automated testing, container image building, and multi-environment deployments. Supports an end-to-end automated delivery chain from development to production.
2. Improve Pipeline Execution Performance
By using sensible caching strategies, parallel job orchestration, and artifact management, you can significantly reduce pipeline execution time. Offers multiple caching options, such as caching
node_modules and Docker layers.3. GitOps and Containerized Deployments
Implement a GitLab-based Kubernetes deployment workflow, supporting automated deployments across multiple environments (staging/production), and using manual approvals to ensure production safety.
Core Features
Multi-Stage Pipeline Architecture
Provides standard three-stage templates: build → test → deploy. Supports customizing stage order and dependencies. Includes code coverage report generation, artifact retention for tests, and conditional execution rules.
Docker Build and Push
Integrates a Docker-in-Docker service to enable automated image building, tagging (commit SHA + latest), and pushing to the GitLab Container Registry. Supports integrated security scanning.
Multi-Environment Deployment Strategy
Reuses YAML templates and leverages GitLab Environments to deploy separately to staging/production. Production supports manual approval gates, and deployment failures trigger automatic rollback.
Common Questions
How do I configure a multi-stage workflow in a GitLab CI pipeline?
In
.gitlab-ci.yml, define a stages list. Each job specifies its stage using the stage field. Stages run in order; jobs within the same stage run in parallel by default. For example:stages: [build, test, deploy]
build-job:
stage: build
test-job:
stage: testHow can I optimize the execution speed of a GitLab CI pipeline?
Key optimization methods include: configuring
cache to cache dependencies (e.g., node_modules), using artifacts to pass build outputs, setting only/rules to avoid unnecessary job runs, and using parallel to run tests concurrently.How do I deploy an application to Kubernetes with GitLab CI?
Use a
kubectl image together with KUBE_CONFIG authentication credentials, then apply deployment manifests via kubectl apply. It’s recommended to use GitLab Environments to track deployment status and configure commands like rollout status to wait for deployment to complete.What is the difference between GitLab Runner and shared Runner?
Shared Runner is provided by GitLab.com and is suitable for small to medium-sized projects. Private Runners are deployed on your own infrastructure, can use custom images and resource limits, and are suitable for enterprise projects with specific security or performance requirements.
How do I implement Docker image build and push in GitLab CI?
Use the
docker:24 image with the docker:24-dind service. Log in to the Container Registry in before_script, then run docker build and docker push in the script.How do I implement automated multi-environment deployments in GitLab CI?
Define common deployment logic using a
.deploy_template YAML anchor to create separate jobs for different environments. Use the environment field to declare environment name and URL. For production, it’s recommended to set when: manual for manual approvals.