GitLab AngularDjangoGitLab CI/CDPython

Article & Tutorial

GitLab CI/CD Pipeline Examples for Python, Angular, and Django Projects

Learn GitLab CI/CD pipeline examples for Python, Angular, and Django projects with lint, test, build, cache, artifacts, Docker, deployment rules, variables, and best practices.

Python, Angular, and Django project pipelines converging on build and deployment
Python, Angular, and Django project pipelines converging on build and deployment
Contents

GitLab CI/CD Pipeline Examples for Python, Angular, and Django Projects

Learn practical GitLab CI/CD pipeline examples for three common project types: Python, Angular, and Django. This guide covers lint, test, build, cache, artifacts, Docker image builds, deployment rules, variables, and best practices.

Table of contents

  • Quick answer
  • Common GitLab pipeline structure
  • Python pipeline example
  • Angular pipeline example
  • Django pipeline example
  • Cache and artifacts
  • Docker image examples
  • Deployment rules
  • Variables and secrets
  • Common mistakes
  • Best practices
  • Related Melochip guides

Quick answer

Python

Use pip, requirements files, pytest, linting, reports, and optional package artifacts.

Angular

Use npm ci, lint, unit tests, production build, and dist/ artifacts.

Django

Use pip, migrations check, tests, collectstatic, Docker image builds, and environment variables.

1. Common GitLab pipeline structure

Most project pipelines can start with a simple structure:

stages: - validate - test - build - package - deploy

The exact commands change by project type, but the idea remains the same: validate code, run tests, build output, package if required, and deploy only when it is safe.

2. GitLab pipeline for Python project

A simple Python project may use requirements.txt , pytest , and optional lint tools such as ruff or flake8 .

image: python:3.12 stages: - validate - test cache: paths: - .cache/pip before_script: - python --version - pip install --cache-dir .cache/pip -r requirements.txt lint_python: stage: validate script: - pip install ruff - ruff check . run_pytest: stage: test script: - pip install pytest pytest-cov - pytest --junitxml=pytest-report.xml --cov=. --cov-report=xml artifacts: when: always reports: junit: pytest-report.xml paths: - coverage.xml

3. GitLab pipeline for Angular project

Angular projects usually use Node.js, npm, lint, tests, and production builds. The most important build output is usually the dist/ folder.

image: node:20 stages: - install - validate - test - build cache: key: files: - package-lock.json paths: - .npm/ install_dependencies: stage: install script: - npm ci --cache .npm --prefer-offline lint_angular: stage: validate script: - npm run lint unit_tests: stage: test script: - npm test -- --watch=false --browsers=ChromeHeadless build_angular: stage: build script: - npm run build -- --configuration production artifacts: paths: - dist/ expire_in: 1 week

4. GitLab pipeline for Django project

Django pipelines normally need dependencies, environment variables, database service setup, migration checks, tests, and static file collection.

image: python:3.12 services: - postgres:16 variables: POSTGRES_DB: test_db POSTGRES_USER: test_user POSTGRES_PASSWORD: test_password DATABASE_URL: postgres://test_user:test_password@postgres:5432/test_db DJANGO_SETTINGS_MODULE: config.settings stages: - validate - test - build before_script: - pip install -r requirements.txt check_migrations: stage: validate script: - python manage.py makemigrations --check --dry-run run_django_tests: stage: test script: - python manage.py test collect_static: stage: build script: - python manage.py collectstatic --noinput artifacts: paths: - staticfiles/ expire_in: 1 week

5. Cache and artifacts by project type

ProjectCache examplesArtifact examples
Pythonpip cache, virtualenv cache if carefully managedtest reports, coverage reports, built packages
Angularnpm cachedist/ , coverage reports
Djangopip cachecoverage reports, static files, Docker image metadata

6. Docker image examples

For production deployments, many teams package Python, Angular, and Django applications as Docker images.

build_docker_image: stage: package image: docker:27 services: - docker:27-dind variables: DOCKER_TLS_CERTDIR: "/certs" IMAGE_TAG: "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" script: - echo "$CI_REGISTRY_PASSWORD" | docker login "$CI_REGISTRY" -u "$CI_REGISTRY_USER" --password-stdin - docker build -t "$IMAGE_TAG" . - docker push "$IMAGE_TAG" rules: - if: '$CI_COMMIT_BRANCH == "main"'

7. Branch rules and deployment jobs

deploy_development: stage: deploy script: - echo "Deploying to development" environment: name: development rules: - if: '$CI_COMMIT_BRANCH == "develop"' deploy_production: stage: deploy script: - echo "Deploying to production" environment: name: production rules: - if: '$CI_COMMIT_BRANCH == "main"' when: manual - when: never

8. Variables and secrets

VariableProject typeRecommended handling
DATABASE_URLDjango/Python backendMasked/protected for real environments.
SECRET_KEYDjangoMasked/protected. Never commit to Git.
API_BASE_URLAngularEnvironment scoped if needed.
CI_REGISTRY_PASSWORDDocker buildUse built-in GitLab registry variables where possible.
KUBE_CONFIGDeploymentUse protected/file variable for production.

Common mistakes

MistakeProblemBetter approach
No lock/dependency fileBuilds become inconsistent.Commit lock files where your ecosystem supports them.
Using cache as deployment outputDeploy job may miss required files.Use artifacts for required output.
Skipping tests before Docker buildBroken code gets packaged.Run lint/tests before packaging.
Hardcoding secretsCredentials can leak.Use GitLab CI/CD variables.
Automatic production deploymentRisky releases can go live.Use manual protected production jobs.

Best practices

  • Keep project-specific commands in package scripts, Makefiles, or documented scripts.
  • Run lint and tests before building Docker images.
  • Use cache only for speed.
  • Use artifacts for build output and reports.
  • Use protected variables for production secrets.
  • Use branch rules and manual production deployments.
  • Use Docker image tags based on commit SHA or release version.
  • Keep CI/CD YAML readable and documented.

Screenshot checklist

  1. Python pipeline showing lint and pytest jobs.
  2. Angular pipeline showing production build and dist/ artifact.
  3. Django pipeline showing migrations check and tests.
  4. Docker image pushed to registry.
  5. Manual production deployment button.
  6. CI/CD variables page with values hidden.
  • GitLab CI/CD Learning Path
  • GitLab Pipeline for Node.js Project
  • GitLab CI/CD YAML Syntax Explained
  • GitLab Artifacts vs Cache Explained
  • GitLab CI/CD Docker Build Pipeline
  • GitLab CI/CD Best Practices for DevOps Teams

Official references

  • GitLab CI/CD YAML syntax reference
  • GitLab CI/CD cache documentation
  • GitLab job artifacts documentation
  • GitLab environments documentation

Conclusion

Python, Angular, and Django projects use different commands, but the GitLab CI/CD pattern is similar: validate, test, build, package, and deploy safely. Once you understand cache, artifacts, variables, Docker images, and deployment rules, you can adapt GitLab pipelines to almost any project type.

Did this help?

Yes No

Join the discussion

0 Comments

Ask questions, add context, or share what worked.

Sign in to join the discussion

No comments yet. Start the discussion.

More from Melochip Editorial

Related articles

Stay in the loop. Get new Melochip articles

Receive Melochip article updates when new articles are available. Explicit opt-in only.

No pre-checked boxes. Unsubscribe support is part of the subscriber foundation.