Create comprehensive GitLab CI/CD pipelines with stages, artifacts, and environments.
You are a GitLab CI/CD expert. Help me create a pipeline configuration.
## Project Details
Framework: ${{FRAMEWORK}}
Deployment: ${{DEPLOYMENT}}
Testing: ${{TESTING}}
Registry: ${{REGISTRY}}
## Please Create:
1. **Complete Pipeline**
```yaml
# .gitlab-ci.yml
stages:
- lint
- test
- build
- security
- deploy-staging
- deploy-production
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
DOCKER_TLS_CERTDIR: "/certs"
default:
image: node:20-alpine
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- node_modules/
.node_template: &node_template
before_script:
- npm ci --cache .npm --prefer-offline
lint:
<<: *node_template
stage: lint
script:
- npm run lint
- npm run type-check
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
test:
<<: *node_template
stage: test
services:
- postgres:15-alpine
variables:
POSTGRES_DB: test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
DATABASE_URL: "postgres://test:test@postgres/test"
script:
- npm run test:ci
coverage: '/All files[^|]*|[^|]*s+([d.]+)/'
artifacts:
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
build:
stage: build
image: docker:24
services:
- docker:24-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build -t $DOCKER_IMAGE .
- docker push $DOCKER_IMAGE
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_TAG
security:
stage: security
image: docker:24
services:
- docker:24-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $DOCKER_IMAGE
- docker run --rm aquasec/trivy image $DOCKER_IMAGE
allow_failure: true
deploy-staging:
stage: deploy-staging
image: bitnami/kubectl:latest
script:
- kubectl config use-context staging
- kubectl set image deployment/app app=$DOCKER_IMAGE
- kubectl rollout status deployment/app
environment:
name: staging
url: https://staging.example.com
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
deploy-production:
stage: deploy-production
image: bitnami/kubectl:latest
script:
- kubectl config use-context production
- kubectl set image deployment/app app=$DOCKER_IMAGE
- kubectl rollout status deployment/app
environment:
name: production
url: https://example.com
rules:
- if: $CI_COMMIT_TAG
when: manual
```
2. **Multi-Project Pipeline**
```yaml
# Trigger downstream pipeline
trigger-deploy:
stage: deploy
trigger:
project: infrastructure/deployment
branch: main
strategy: depend
variables:
DEPLOY_VERSION: $CI_COMMIT_SHA
```
3. **Dynamic Environments**
```yaml
deploy-review:
stage: deploy
script:
- deploy_to_review_app
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://$CI_COMMIT_REF_SLUG.review.example.com
on_stop: stop-review
rules:
- if: $CI_MERGE_REQUEST_ID
stop-review:
stage: deploy
script:
- delete_review_app
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
when: manual
```
4. **Parallel Testing**
```yaml
test:
stage: test
parallel:
matrix:
- NODE_VERSION: ["18", "20", "22"]
image: node:$NODE_VERSION
script:
- npm test
```
5. **Artifacts & Dependencies**
```yaml
build:
stage: build
script:
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 week
deploy:
stage: deploy
dependencies:
- build
script:
- deploy_dist_folder
```
6. **Secrets Management**
```yaml
# Use CI/CD variables for secrets
deploy:
script:
- echo "$KUBE_CONFIG" | base64 -d > kubeconfig
- export KUBECONFIG=kubeconfig
- kubectl apply -f manifests/
```
7. **Include Templates**
```yaml
include:
- template: Security/SAST.gitlab-ci.yml
- template: Security/Dependency-Scanning.gitlab-ci.yml
- local: .gitlab/ci/build.yml
- project: 'shared/ci-templates'
ref: main
file: '/templates/deploy.yml'
```
8. **Auto DevOps**
```yaml
# Enable Auto DevOps with customization
include:
- template: Auto-DevOps.gitlab-ci.yml
variables:
AUTO_DEVOPS_BUILD_IMAGE_CNB_ENABLED: "true"
AUTO_DEVOPS_DEPLOY_DEBUG: "true"
STAGING_ENABLED: "true"
```Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{FRAMEWORK][{DEPLOYMENT][{TESTING][{REGISTRY]