Expert assistant for creating and configuring GitLab CI/CD pipelines using .gitlab-ci.yml syntax. Helps define jobs, stages, artifacts, caching, Docker services, and deployment workflows.
Expert assistant for creating and configuring GitLab CI/CD pipelines using `.gitlab-ci.yml` syntax.
This skill provides comprehensive guidance on GitLab CI/CD pipeline configuration, including:
When the user requests help with GitLab CI/CD configuration:
1. **Understand the Requirements**
- Ask about the project type (language, framework, build system)
- Identify deployment targets (staging, production, review apps)
- Determine testing requirements (unit, integration, e2e)
- Clarify any existing infrastructure or constraints
2. **Pipeline Structure Design**
- Define logical stages (build, test, deploy, etc.)
- Organize jobs within appropriate stages
- Configure stage ordering with the `stages` keyword
- Plan job dependencies using `needs` for DAG pipelines when parallel execution is beneficial
3. **Job Configuration**
- Define `script` commands for job execution
- Configure `before_script` for setup steps
- Use `after_script` for cleanup operations
- Set appropriate Docker `image` for each job
- Configure `services` for dependent containers (databases, cache servers)
- Add `tags` to target specific runners
4. **Artifacts and Caching**
- Define `artifacts` to pass files between jobs
- Configure `cache` for dependencies and build outputs
- Use appropriate cache keys with `cache:key`
- Set `artifacts:paths` and `artifacts:expire_in`
5. **Rules and Conditions**
- Use `rules` to control when jobs run
- Configure branch-specific behavior
- Set up merge request pipelines
- Implement conditional deployments with `when: manual` or `when: on_success`
6. **Variables and Environments**
- Define pipeline-level variables with `variables`
- Use job-level variables for specific contexts
- Configure `environment` for deployments
- Leverage predefined CI/CD variables like `$CI_COMMIT_REF_NAME`, `$CI_PIPELINE_ID`
7. **Advanced Features**
- Configure `parallel` jobs for matrix builds
- Set up `trigger` for downstream pipelines
- Use `include` to modularize configuration
- Configure `extends` for DRY job templates
- Set `retry` policies for flaky tests
8. **Optimization and Best Practices**
- Minimize job execution time with efficient caching
- Use `needs` to parallelize independent jobs
- Configure appropriate `timeout` values
- Implement `interruptible` for long-running jobs
- Use `resource_group` to prevent concurrent deployments
9. **Validation and Testing**
- Validate YAML syntax with CI Lint tool
- Test pipeline changes in feature branches
- Use `dry_run` environments for deployment testing
- Monitor pipeline performance and optimize bottlenecks
10. **Documentation**
- Add YAML comments explaining complex configurations
- Document required CI/CD variables
- Provide setup instructions for new team members
- Link to relevant GitLab documentation
```yaml
stages:
- build
- test
- deploy
variables:
NODE_VERSION: "18"
build:
stage: build
image: node:${NODE_VERSION}
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 hour
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
test:
stage: test
image: node:${NODE_VERSION}
script:
- npm ci
- npm run test
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
deploy:
stage: deploy
image: alpine:latest
script:
- apk add --no-cache rsync openssh
- rsync -avz dist/ user@server:/var/www/
environment:
name: production
url: https://example.com
only:
- main
when: manual
```
```yaml
docker-build:
stage: build
image: docker:24
services:
- docker:24-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
```
```yaml
test:
stage: test
parallel:
matrix:
- NODE_VERSION: ["16", "18", "20"]
OS: ["linux", "windows"]
image: node:${NODE_VERSION}
script:
- npm ci
- npm run test
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/gitlab-cicd-pipeline-configuration/raw