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.
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.
Build, test, deploy, verify
The core rule: build one immutable artifact, test it thoroughly, and promote that same artifact through every environment.
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
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
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
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 type | Lint & format | Tests & coverage | SAST & config scanning | Dependencies (SCA) |
|---|---|---|---|---|
| Java / Kotlin | Checkstyle, SpotBugs | JUnit + JaCoCo | SonarQube, Semgrep | OWASP Dependency-Check |
| JavaScript / TypeScript | ESLint, Prettier | Jest or Vitest + coverage | SonarQube, Semgrep | npm audit, Dependency-Check |
| Python | Ruff, Black | pytest + coverage.py | Bandit, Semgrep, SonarQube | pip-audit |
| Go | golangci-lint, gofmt | go test -cover | gosec, Semgrep | govulncheck |
| PHP | PHP_CodeSniffer, PHPStan | PHPUnit | SonarQube, Semgrep | composer audit |
| .NET | dotnet format, analyzers | xUnit / NUnit + Coverlet | SonarQube, Semgrep | dotnet list package --vulnerable |
| Dockerfiles & images | Hadolint | container-structure-test | Trivy (config) | Trivy image, Grype |
| Terraform | terraform fmt / validate, TFLint | terraform test, Terratest | Checkov, Trivy (config) | Pinned providers & modules |
| Kubernetes & Helm | kubeconform, helm lint | helm template + policy tests | Checkov, Kubesec | Trivy (cluster images) |
| Shell scripts | ShellCheck, shfmt | Bats | Semgrep | — |
| Ansible | ansible-lint | Molecule | Checkov | Pinned collections |
| Every repository | Commit & MR rules | Required pipeline | Gitleaks (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.
# 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: manualWant 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.