agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/devops/gitlab-ci/SKILL.md

gitlab-ci

Skill15 starsChanged 41 days agoMITView on GitHub

Expert GitLab CI/CD assistance covering .gitlab-ci.yml, stages, artifacts, caching, GitLab Runners, and Auto DevOps. Use when configuring continuous integration and deployment pipelines on GitLab.

5 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. 0 are common, 1 is distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use .gitlab-ci.yml stages with rules: conditions:

    line 153
  2. Very specific:

    Use rules:changes in monorepos to avoid running redundant jobs when unrelated code is modified.

    line 185
  3. Distinctive:

    Use GitLab Dependency Proxy to cache container images from Docker Hub, eliminating rate limit throttling.

    line 187
  4. Very specific:

    Use deprecated only/except syntax.

    line 192
  5. Very specific:

    Run Docker-in-Docker (dind) with privileged flags in shared environments.

    line 194

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

GitLab CI/CD

GitLab CI/CD provides integrated pipeline orchestration directly within GitLab repositories, utilizing reusable CI Components and container-native runners for automated software delivery.

When to Use

  • Self-Hosted & Enterprise GitOps CI/CD: Running pipelines within GitLab EE/CE and private runner infrastructures.
  • Container Registry & Helm Package Integration: Built-in GitLab Container Registry, Package Registry, and Dependency Proxy.
  • Multi-Project & Downstream Pipelines: Triggering coordinated cross-repository builds in complex enterprise architectures.
  • Dynamic Parent-Child Pipelines: Generating build steps dynamically at runtime based on modified monorepo paths.

Quick Start

# .gitlab-ci.yml
stages:
  - build
  - test

build-job:
  stage: build
  image: node:20
  script:
    - npm ci
    - npm run build
  artifacts:
    paths:
      - dist/

test-job:
  stage: test
  image: node:20
  script:
    - npm test
  needs: [build-job]

Core Concepts

Declarative Pipeline with Stages, Caching & Artifacts

Clean, structured .gitlab-ci.yml pipeline:

# .gitlab-ci.yml
stages:
  - lint
  - test
  - build
  - deploy

default:
  image: node:22-alpine
  cache:
    key:
      files:
        - package-lock.json
    paths:
      - .npm/

variables:
  npm_config_cache: "$CI_PROJECT_DIR/.npm"

lint:
  stage: lint
  script:
    - npm ci
    - npm run lint
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

test:
  stage: test
  script:
    - npm ci
    - npm test -- --ci --reporters=default --reporters=jest-junit
  artifacts:
    when: always
    reports:
      junit: junit.xml
      coverage_report:
        coverage_format: cobertura
        path: coverage/cobertura-coverage.xml

build-container:
  stage: build
  image: docker:27-cli
  services:
    - docker:27-dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Monorepo Path Filtering with rules:changes

Executing jobs only when relevant subdirectories are modified:

frontend-job:
  stage: test
  script:
    - cd frontend && npm test
  rules:
    - changes:
        - frontend/**/*

backend-job:
  stage: test
  script:
    - cd backend && cargo test
  rules:
    - changes:
        - backend/**/*

Protected Environments & Manual Deployment Gates

Requiring manual approval for production releases:

deploy-production:
  stage: deploy
  environment:
    name: production
    url: https://api.example.com
  script:
    - echo "Deploying version $CI_COMMIT_SHA to production cluster"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual # Requires manual trigger in GitLab UI

Common Patterns

Multi-Stage Pipeline with Artifact Passing and Rule Conditions

Problem: Running tests and security scans on draft branches before code is ready for deployment.

Solution: Use .gitlab-ci.yml stages with rules: conditions:

stages:
  - test
  - deploy

run_tests:
  stage: test
  image: node:20-alpine
  script:
    - npm ci
    - npm test
  artifacts:
    when: on_failure
    paths:
      - test-results/

deploy_prod:
  stage: deploy
  image: alpine/k8s:1.28.2
  script:
    - kubectl apply -f k8s/production/
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: manual

Best Practices

Do:

  • Use rules:changes in monorepos to avoid running redundant jobs when unrelated code is modified.
  • Configure GitLab reports:junit and reports:coverage_report to view test insights in merge requests.
  • Use GitLab Dependency Proxy to cache container images from Docker Hub, eliminating rate limit throttling.
  • Mark production deploy jobs with when: manual and assign them to protected environments with approver policies.

Don't:

  • Use deprecated only/except syntax; migrate to modern rules: directives.
  • Store plaintext passwords in .gitlab-ci.yml; use Masked and Protected CI/CD Variables.
  • Run Docker-in-Docker (dind) with privileged flags in shared environments; use Kaniko for rootless builds.

Troubleshooting

ErrorCauseSolution
yaml invalid: jobs:run_tests config key may not be used withIncompatible keyword combinations (e.g. only used with rules).Migrate legacy only/except syntax to modern rules: conditions.
Job failed: execution took longer than ...Job exceeded runner timeout setting.Increase timeout in project Settings > CI/CD > General pipelines.
Artifacts not found in downstream jobArtifact expiration reached or dependencies: list omitted.Explicitly declare dependencies: [build_job] in the consumer job.

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.