Skip to content

16 Ci Cd Pipeline

DodaTech 3 min read

title: "CI/CD Pipeline Integration" description: "Integrate API tests into CI/CD pipelines using GitHub Actions, Jenkins, GitLab CI, and CircleCI. Learn test stages, parallel execution, artifact management, and deployment gates based on test results." weight: 16 date: 2026-06-28 lastmod: 2026-06-28 tags: [api-development, testing] }

Integrating API tests into CI/CD pipelines ensures every code change is validated before deployment. Tests run automatically, generate reports, and act as quality gates. Proper integration catches issues early and prevents bad deployments.

What You'll Learn

  • CI/CD pipeline stages for API testing
  • GitHub Actions workflow configuration
  • Parallel test execution strategies
  • Test artifact and report management
  • Deployment gates based on test results

Why It Matters

Manual testing does not scale. CI/CD integration ensures every commit is tested consistently. Failed tests block deployments, preventing regressions from reaching production.

Real-World Use

GitHub runs API tests on every pull request. Stripe's CI pipeline includes security, contract, and performance tests. Netflix's CI/CD pipeline runs thousands of API tests in parallel.

flowchart LR
    Commit[Code Commit] --> Build[Build Stage]
    Build --> Unit[Unit Tests]
    Build --> Lint[Lint & Type Check]
    Unit --> API[API Tests]
    API --> Integration[Integration Tests]
    Integration --> Security[Security Tests]
    Security --> Artifact[Build Artifact]
    Artifact --> Staging[Deploy to Staging]
    Staging --> E2E[E2E Tests]
    E2E --> Production[Deploy to Production]

Teacher Mindset

Run fast tests first (unit, lint). Run API and integration tests on every PR. Run security and load tests on merge to main. Fail the build if any test stage fails. Keep test execution under 10 minutes.

Code Examples

# Example 1: GitHub Actions for API tests
name: API Tests
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_PASSWORD: testpass
        ports:
          - 5432:5432
      redis:
        image: redis:7
        ports:
          - 6379:6379

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'

      - run: npm ci
      - run: npm test -- --coverage
        env:
          DATABASE_URL: postgres://postgres:testpass@localhost:5432/postgres
          REDIS_URL: redis://localhost:6379

      - uses: actions/upload-artifact@v3
        if: success() || failure()
        with:
          name: test-reports
          path: reports/
// Example 2: Jenkins pipeline
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'npm ci'
            }
        }
        stage('Unit Tests') {
            steps {
                sh 'npm run test:unit'
            }
        }
        stage('API Tests') {
            parallel {
                stage('Integration') {
                    steps {
                        sh 'npm run test:integration'
                    }
                }
                stage('Contract') {
                    steps {
                        sh 'npm run test:contract -- --publish'
                    }
                }
                stage('Security') {
                    steps {
                        sh 'npm run test:security'
                    }
                }
            }
        }
        stage('Performance') {
            when { branch 'main' }
            steps {
                sh 'k6 run tests/load/script.js'
            }
        }
    }
    post {
        always {
            junit 'reports/**/*.xml'
            publishHTML target: [reportDir: 'reports/html', reportName: 'Test Report']
        }
    }
}
# Example 3: GitLab CI
stages:
  - test
  - security
  - performance

api-tests:
  stage: test
  image: node:18
  services:
    - postgres:15
  variables:
    DATABASE_URL: postgres://postgres:testpass@postgres:5432/test
  script:
    - npm ci
    - npm run test:api
  artifacts:
    reports:
      junit: reports/junit.xml
    paths:
      - reports/

security-scan:
  stage: security
  script:
    - npm run test:security
  only:
    - main

load-test:
  stage: performance
  image: grafana/k6
  script:
    - k6 run tests/load/script.js --summary-export reports/k6.json
  only:
    - main

Common Mistakes

  • Running all tests sequentially instead of in parallel
  • Not using service containers for external dependencies
  • Ignoring test failures and deploying anyway
  • Not storing test reports as build artifacts
  • Running slow performance tests on every commit instead of on main

Practice

  1. Create a GitHub Actions workflow that runs API tests on PR.
  2. Add parallel test execution for unit, integration, and security tests.
  3. Configure a service container (PostgreSQL) for integration tests.
  4. Publish test reports as build artifacts.
  5. Challenge: Create a deployment gate that requires API tests to pass before deploying to staging.

FAQ

How fast should CI tests be?

Aim for under 10 minutes for the full test suite. Run fast tests on every commit and slow tests less frequently.

Should I run API tests in parallel?

Yes. Parallel execution reduces feedback time. Ensure tests are isolated and do not share state.

How do I handle test databases in CI?

Use service containers (Docker) for databases. Run migrations before tests and clean up after.

What if my tests need external API access?

Mock external APIs. Do not depend on external services in CI tests.

How do I manage test secrets in CI?

Use CI/CD secret management. Pass them as environment variables, never hardcode in test files.

Mini Project

Set up a complete CI/CD pipeline for an API project: GitHub Actions workflow with unit and API tests, service containers for Postgres/Redis, parallel test stages, JUnit test reporting, and deployment gate that requires all tests to pass.

What's Next

Next, you will learn about test reporting with Allure and Newman reporters.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro