GITLAB CI/CD · DEVSECOPS

One GitLab pipeline to build, test, secure, deploy and verify every change.

We design GitLab pipelines as reusable templates: every merge request is linted, built, tested and scanned, and every release is deployed the same way, verified automatically and promoted to production behind an approval.

TOOLS IN THIS SOLUTION

Common technologies and the role each can play.

  • GitLabPipeline orchestration
  • SonarQubeCode quality
  • TrivySecurity scanning
  • KubernetesDeployment platform

Tools are selected for your environment. Product names identify the technologies discussed and do not imply endorsement.

Pipeline stages: lint (hadolint, shellcheck, yamllint, tf-fmt); build (app-build, docker-build); test (unit-tests, integration, coverage); quality (sonarqube, quality-gate); security (semgrep-sast, gitleaks, dep-check, trivy-image, checkov-iac); package (sbom, dtrack-upload, cosign-sign, tag-release); staging (deploy-stg); verify (smoke-tests, zap-baseline, k6-load); production (deploy-prod, post-deploy)linthadolintshellcheckyamllinttf-fmtbuildapp-builddocker-buildtestunit-testsintegrationcoveragequalitysonarqubequality-gatesecuritysemgrep-sastgitleaksdep-checktrivy-imagecheckov-iacpackagesbomdtrack-uploadcosign-signtag-releasestagingdeploy-stgverifysmoke-testszap-baselinek6-loadproductiondeploy-prodpost-deploypassedmanual (protected environment)
An example merge-request-to-production pipeline as it appears in GitLab: each column is a stage, each pill a job. Production deployment is a manual, protected job.

Build, test, deploy, verify

The core rule: build one immutable artifact, test it thoroughly, and promote that same artifact through every environment.

Build, then test, then deploy, then verify, with feedback from verify back to build1. BuildCompile & packageContainer imageTagged by commit SHA2. TestUnit & integrationQuality gateSecurity scans3. DeploySame artifactStaging, then prodRolling or canary4. VerifySmoke & DASTMetrics & alertsAuto rollbackfeedback: failed checks stop the pipeline and notify the author
Every change follows the same four steps. The artifact built once in step 1 is the one promoted to every environment.
STEP 1

Build

Compile, package and build a container image once per commit, tagged with the commit SHA and pushed to the GitLab registry.

  • Reproducible builds with pinned base images
  • Dependency caching for fast pipelines
  • Hadolint, ShellCheck and linters run first
STEP 2

Test

Unit and integration tests, coverage, code quality and security scans run in parallel on every merge request.

  • SonarQube quality gate blocks the merge
  • Semgrep, Gitleaks, Dependency-Check, Trivy, Checkov
  • Results shown directly on the merge request
STEP 3

Deploy

The tested image is deployed to staging automatically, then to production through a protected, approved job.

  • Helm or Terraform with environment-specific values
  • Rolling or canary releases
  • Deployment history per environment
STEP 4

Verify

Smoke tests, an OWASP ZAP baseline scan and load checks run against staging; production is watched through metrics and alerts.

  • Atomic deploys roll back on failure
  • Prometheus alerts tied to the release
  • Post-deploy health checks

Code checks for every language and file type

Each repository gets the right linters, tests and scanners for what it contains. A typical mapping:

Code / file typeLint & formatTests & coverageSAST & config scanningDependencies (SCA)
Java / KotlinCheckstyle, SpotBugsJUnit + JaCoCoSonarQube, SemgrepOWASP Dependency-Check
JavaScript / TypeScriptESLint, PrettierJest or Vitest + coverageSonarQube, Semgrepnpm audit, Dependency-Check
PythonRuff, Blackpytest + coverage.pyBandit, Semgrep, SonarQubepip-audit
Gogolangci-lint, gofmtgo test -covergosec, Semgrepgovulncheck
PHPPHP_CodeSniffer, PHPStanPHPUnitSonarQube, Semgrepcomposer audit
.NETdotnet format, analyzersxUnit / NUnit + CoverletSonarQube, Semgrepdotnet list package --vulnerable
Dockerfiles & imagesHadolintcontainer-structure-testTrivy (config)Trivy image, Grype
Terraformterraform fmt / validate, TFLintterraform test, TerratestCheckov, Trivy (config)Pinned providers & modules
Kubernetes & Helmkubeconform, helm linthelm template + policy testsCheckov, KubesecTrivy (cluster images)
Shell scriptsShellCheck, shfmtBatsSemgrep—
Ansibleansible-lintMoleculeCheckovPinned collections
Every repositoryCommit & MR rulesRequired pipelineGitleaks (secrets)SBOM → Dependency-Track

Security and quality gates explained

SonarQube

Code quality, coverage, duplication and maintainability with a quality gate that can block merges.

Semgrep

Fast, rule-based static analysis (SAST) across many languages, with custom rules for your codebase.

Gitleaks

Detects passwords, tokens and keys committed to Git history before they reach production.

Hadolint

Lints Dockerfiles against best practices for smaller, safer and more predictable images.

OWASP Dependency-Check

Finds known-vulnerable libraries in your dependencies and can fail builds above a CVSS threshold.

Dependency-Track

Ingests SBOMs from every release and keeps monitoring them, alerting when a new vulnerability affects a deployed version.

Trivy

Scans container images, filesystems and IaC for vulnerabilities and misconfiguration; also generates CycloneDX SBOMs.

Checkov

Policy checks for Terraform, Kubernetes manifests, Helm and Dockerfiles before anything is applied.

OWASP ZAP

Dynamic baseline scan (DAST) of the running staging application for common web weaknesses.

Sample pipeline

A condensed example of the jobs in the graph above. In real projects we split this into reusable include templates shared across repositories.

.gitlab-ci.yml (illustrative)
# Illustrative .gitlab-ci.yml: pin image versions or digests and adapt jobs to your stack.
stages: [lint, build, test, quality, security, package, staging, verify, production]

variables:
  IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

hadolint:
  stage: lint
  image: hadolint/hadolint:latest-debian
  script: hadolint Dockerfile

docker-build:                       # build once, push by commit SHA
  stage: build
  image: docker:27
  services: [docker:27-dind]
  script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
    - docker build -t "$IMAGE" .
    - docker push "$IMAGE"

unit-tests:
  stage: test
  image: node:22                    # use your language's image
  script: [npm ci, npm test]
  artifacts:
    reports: { junit: junit.xml }

sonarqube:                          # fails the pipeline if the quality gate fails
  stage: quality
  image: { name: sonarsource/sonar-scanner-cli:latest, entrypoint: [""] }
  variables: { GIT_DEPTH: "0" }     # SONAR_HOST_URL and SONAR_TOKEN as masked variables
  script: sonar-scanner -Dsonar.qualitygate.wait=true

semgrep-sast:
  stage: security
  image: semgrep/semgrep:latest
  script: semgrep scan --config p/default --error

gitleaks:
  stage: security
  image: { name: zricethezav/gitleaks:latest, entrypoint: [""] }
  variables: { GIT_DEPTH: "0" }
  script: gitleaks git --redact --verbose .

dep-check:
  stage: security
  image: { name: owasp/dependency-check:latest, entrypoint: [""] }
  script:
    - /usr/share/dependency-check/bin/dependency-check.sh --scan . --format HTML --failOnCVSS 7 --nvdApiKey "$NVD_API_KEY"
  artifacts: { paths: [dependency-check-report.html], when: always }

trivy-image:
  stage: security
  image: { name: aquasec/trivy:latest, entrypoint: [""] }
  variables: { TRIVY_USERNAME: $CI_REGISTRY_USER, TRIVY_PASSWORD: $CI_REGISTRY_PASSWORD }
  script: trivy image --exit-code 1 --severity HIGH,CRITICAL "$IMAGE"

checkov-iac:
  stage: security
  image: { name: bridgecrew/checkov:latest, entrypoint: [""] }
  script: checkov -d infra/ --quiet

sbom:
  stage: package
  image: { name: aquasec/trivy:latest, entrypoint: [""] }
  variables: { TRIVY_USERNAME: $CI_REGISTRY_USER, TRIVY_PASSWORD: $CI_REGISTRY_PASSWORD }
  script: trivy image --format cyclonedx --output sbom.json "$IMAGE"
  artifacts: { paths: [sbom.json] }

dtrack-upload:                      # continuous monitoring of every released component
  stage: package
  image: curlimages/curl:latest
  needs: [sbom]
  script:
    - >
      curl --fail -X POST "$DTRACK_URL/api/v1/bom" -H "X-Api-Key: $DTRACK_API_KEY"
      -F autoCreate=true -F projectName="$CI_PROJECT_PATH"
      -F projectVersion="$CI_COMMIT_SHORT_SHA" -F bom=@sbom.json

deploy-stg:
  stage: staging
  image: alpine/helm:latest         # cluster access via the GitLab agent for Kubernetes
  environment: { name: staging, url: https://staging.example.com }
  script: helm upgrade --install app ./chart --set image.tag=$CI_COMMIT_SHORT_SHA --wait
  rules: [{ if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH }]

zap-baseline:
  stage: verify
  image: ghcr.io/zaproxy/zaproxy:stable
  script: zap-baseline.py -t https://staging.example.com
  rules: [{ if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH }]

deploy-prod:                        # protected environment: approvers required
  stage: production
  image: alpine/helm:latest
  environment: { name: production, url: https://example.com }
  script: helm upgrade --install app ./chart --set image.tag=$CI_COMMIT_SHORT_SHA --wait --atomic
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: manual

Want this running in your team?

Tell us about your stack, cloud and delivery goals. We will propose a scope, a timeline and the first quick wins.

Start a conversation