Docs/CI/CD Integration/GitLab CI

GitLab CI

Integrate DepAegis into your GitLab CI/CD pipelines to publish npm packages, NuGet packages, and Docker images automatically on tags and merges.

Setting Up Your DepAegis Token

Store your DepAegis Personal Access Token as a CI/CD variable in GitLab:

  1. Create a token in the DepAegis dashboard under Settings → Access Tokens. Use the Read & Write scope for publishing.
  2. In GitLab, navigate to your project (or group) and go to Settings → CI/CD → Variables.
  3. Click Add variable. Set the key to DEPAEGIS_TOKEN, paste the token as the value, and enable Mask variable and Protect variable.
Mark the variable as Protected so it is only available in protected branches and tags. This prevents unauthorized pipelines from accessing your token.

Publishing npm Packages

Add a publish stage to your .gitlab-ci.yml that runs on version tags:

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

test:
  stage: test
  image: node:20
  script:
    - npm ci
    - npm test
  rules:
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_MERGE_REQUEST_IID'

publish-npm:
  stage: publish
  image: node:20
  script:
    - npm ci
    - npm run build
    - |
      cat > .npmrc <<EOF
      //app.depaegis.com/:_authToken=${DEPAEGIS_TOKEN}
      @my-org:registry=https://app.depaegis.com/api/v1/npm/
      EOF
    - npm publish
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+/'
The .npmrc is written at build time from the CI variable. Never commit .npmrc files containing tokens to the repository.

Publishing NuGet Packages

Build and push .NET packages using the dotnet CLI:

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

test:
  stage: test
  image: mcr.microsoft.com/dotnet/sdk:10.0
  script:
    - dotnet test
  rules:
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_MERGE_REQUEST_IID'

publish-nuget:
  stage: publish
  image: mcr.microsoft.com/dotnet/sdk:10.0
  script:
    - dotnet pack MyPackage.csproj -c Release -o ./artifacts
    - |
      dotnet nuget push ./artifacts/*.nupkg \
        --source "https://nuget.app.depaegis.com/api/v1/nuget/v3/index.json" \
        --api-key "$DEPAEGIS_TOKEN" \
        --skip-duplicate
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+/'

Pushing Docker Images

Build and push container images using Docker-in-Docker:

# .gitlab-ci.yml
stages:
  - publish

publish-docker:
  stage: publish
  image: docker:27
  services:
    - docker:27-dind
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - echo "$DEPAEGIS_TOKEN" | docker login app.depaegis.com -u "$CI_REGISTRY_USER" --password-stdin
  script:
    - docker build -t app.depaegis.com/my-org/my-app:$CI_COMMIT_TAG .
    - docker tag app.depaegis.com/my-org/my-app:$CI_COMMIT_TAG app.depaegis.com/my-org/my-app:latest
    - docker push app.depaegis.com/my-org/my-app:$CI_COMMIT_TAG
    - docker push app.depaegis.com/my-org/my-app:latest
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+/'
Replace $CI_REGISTRY_USER with your actual DepAegis username, or use a service account name. The password is the DEPAEGIS_TOKEN.

Full Pipeline Example

A combined pipeline with test, npm publish, NuGet publish, and Docker publish stages:

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

variables:
  NPM_REGISTRY: "https://app.depaegis.com/"
  NUGET_SOURCE: "https://nuget.app.depaegis.com/api/v1/nuget/v3/index.json"
  DOCKER_REGISTRY: "app.depaegis.com"

# ── Test ────────────────────────────────────────────────
test-node:
  stage: test
  image: node:20
  script:
    - npm ci
    - npm test
  rules:
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_MERGE_REQUEST_IID'

test-dotnet:
  stage: test
  image: mcr.microsoft.com/dotnet/sdk:10.0
  script:
    - dotnet test
  rules:
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_MERGE_REQUEST_IID'

# ── Publish ─────────────────────────────────────────────
publish-npm:
  stage: publish
  image: node:20
  needs: [test-node]
  script:
    - npm ci
    - npm run build
    - |
      cat > .npmrc <<EOF
      //app.depaegis.com/:_authToken=${DEPAEGIS_TOKEN}
      @my-org:registry=https://app.depaegis.com/api/v1/npm/
      EOF
    - npm publish
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+/'

publish-nuget:
  stage: publish
  image: mcr.microsoft.com/dotnet/sdk:10.0
  needs: [test-dotnet]
  script:
    - dotnet pack MyPackage.csproj -c Release -o ./artifacts
    - dotnet nuget push ./artifacts/*.nupkg --source "$NUGET_SOURCE" --api-key "$DEPAEGIS_TOKEN" --skip-duplicate
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+/'

publish-docker:
  stage: publish
  image: docker:27
  services:
    - docker:27-dind
  needs: [test-node]
  variables:
    DOCKER_TLS_CERTDIR: "/certs"
  before_script:
    - echo "$DEPAEGIS_TOKEN" | docker login $DOCKER_REGISTRY -u gitlab-ci --password-stdin
  script:
    - docker build -t $DOCKER_REGISTRY/my-org/my-app:$CI_COMMIT_TAG .
    - docker push $DOCKER_REGISTRY/my-org/my-app:$CI_COMMIT_TAG
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+/'

Caching Strategies

Speed up pipelines by caching package downloads between runs. GitLab CI supports cache directives per job.

# Add to any Node.js job
cache:
  key:
    files:
      - package-lock.json
  paths:
    - node_modules/

script:
  - npm ci   # uses cache if available
# Add to any .NET job
cache:
  key:
    files:
      - MyPackage.csproj
  paths:
    - ~/.nuget/packages/

script:
  - dotnet restore   # uses cache if available
# Use BuildKit cache with a local mount
variables:
  DOCKER_BUILDKIT: "1"

script:
  - |
    docker build       --cache-from type=local,src=/cache       --cache-to type=local,dest=/cache,mode=max       -t app.depaegis.com/my-org/my-app:$CI_COMMIT_TAG .

cache:
  key: docker-build-cache
  paths:
    - /cache/
For shared runners, consider using the dependency proxy or a shared cache backed by object storage (S3, GCS) for better cache hit rates across runners.