Configure a GitLab CI/CD Pipeline with Multi-Stage Deployment

Create a production-grade GitLab CI/CD pipeline with linting, testing, security scanning, and multi-environment deployments.

๐Ÿ“ The Prompt

Generate a complete `.gitlab-ci.yml` configuration for a [PROJECT_TYPE] project (e.g., Python microservice, React SPA, Go CLI tool) that implements a multi-stage CI/CD pipeline. **Project Context:** - Language/Runtime: [LANGUAGE_AND_VERSION] - Build tool: [BUILD_TOOL] - Deployment targets: [DEPLOYMENT_TARGETS] (e.g., AWS ECS, Kubernetes, S3 + CloudFront) - Branch strategy: `main` (production), `develop` (staging), feature branches (review) **Pipeline Stages to Include:** 1. **๐Ÿ” Lint & Static Analysis**: Run [LINTER_TOOLS] with fail-on-warning. Cache linter dependencies. 2. **๐Ÿงช Test**: Execute unit and integration tests with coverage threshold of [COVERAGE_PERCENT]%. Generate JUnit XML reports and Cobertura coverage reports for GitLab merge request integration. 3. **๐Ÿ—๏ธ Build**: Compile/bundle the application. For containerized apps, build a Docker image using multi-stage Dockerfile, tag with `$CI_COMMIT_SHORT_SHA` and `latest`, and push to [CONTAINER_REGISTRY]. 4. **๐Ÿ”’ Security Scan**: Integrate SAST, dependency scanning, and container scanning using GitLab templates or [SECURITY_TOOL]. 5. **๐Ÿš€ Deploy Staging**: Auto-deploy to staging on `develop` branch merges. Use [DEPLOYMENT_METHOD] with environment URL and rollback capability. 6. **๐Ÿš€ Deploy Production**: Manual approval gate for production deployment from `main`. Include smoke test job that runs after deployment. **Also include:** - Global caching strategy for [DEPENDENCY_MANAGER] (e.g., npm, pip, go mod) - `rules:` syntax (not `only/except`) for conditional job execution - Environment-specific variables using GitLab CI/CD variable groups - `needs:` for DAG pipeline optimization - Retry configuration for flaky network-dependent jobs - Clear inline comments explaining each decision

๐Ÿ’ก Tips for Better Results

Specify your exact runner tags and executor type (Docker, Kubernetes, shell) since image availability and caching strategies differ significantly. Use the `needs` keyword to create a DAG pipeline โ€” this can cut total pipeline time by 40-60% compared to sequential stages. Store secrets as masked and protected CI/CD variables and reference them by name in your prompt so the output uses proper variable substitution.

๐ŸŽฏ Use Cases

DevOps engineers and development teams use this when setting up or modernizing their GitLab CI/CD pipeline, especially during new project bootstrapping or migration from other CI systems like Jenkins or GitHub Actions.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Create a GitHub Actions CI/CD Workflow for Automated Testing and Deployment

Generate a complete GitHub Actions CI/CD workflow with build, test, deploy, and notification jobs for your project.