Skip to content
Cloud Computing

CI CD Pipeline: Stages, Examples and Best Practices

Learn how a CI/CD pipeline builds, tests and prepares software for release. Explore common stages, practical GitHub Actions and Jenkins examples, and ways to make deployments safer.

Updated 9 min read 5 views
CI CD Pipeline: Stages, Examples and Best Practices

A ci cd pipeline moves code changes through integration, testing and release in a repeatable way. For developers and small businesses, the value is not automation for its own sake. A well-designed pipeline makes failures easier to find, cuts manual release work and gives you a clearer, safer route to production.

A Continuous Integration and Continuous Delivery or Deployment (CI/CD) pipeline is an automated sequence that builds, tests and prepares software changes for release. Continuous Integration checks changes as developers combine them. Continuous Delivery keeps validated changes ready to deploy, and Continuous Deployment releases them automatically. Together, these practices make software delivery more consistent and give you earlier feedback when a change has a problem.

Understanding CI/CD Pipeline

A CI/CD pipeline is essential in modern software development as it streamlines the process of delivering high-quality software. By automating the integration and deployment processes, teams can focus on writing code rather than managing releases.

Continuous Integration (CI) involves regularly merging code changes into a shared repository, where automated builds and tests are run to ensure the changes do not introduce errors. Continuous Delivery (CD) keeps these validated changes ready for release, often requiring manual approval for deployment. Continuous Deployment takes this a step further by automatically releasing changes that meet predefined criteria.

What is a ci cd pipeline?

A ci cd pipeline is a set of automated steps that takes a code change from a source repository to a tested, releasable build. You define those steps in a configuration file or a CI/CD service, then run them when an event such as a code push or pull request occurs. Red Hat describes the pipeline as a path for building, testing and deploying code.

Continuous Integration (CI) means regularly merging code changes into a shared repository and checking them with automated builds and tests. Continuous Delivery (CD) means keeping tested changes ready for release, often with a person approving the production deployment. Continuous Deployment means changes that meet the pipeline's release conditions go to production automatically.

People sometimes write CD/CI instead of CI/CD. Both refer to the same practices, though CI/CD is the more common term. The pipeline is more than a deployment script. It is the repeatable process that verifies changes and moves them toward users.

Practice What happens Typical release control
Continuous Integration Build and test changes as they enter a shared codebase. A failed check blocks or flags the change.
Continuous Delivery Keep validated software ready for a release. A person or release process approves production deployment.
Continuous Deployment Release changes automatically after required checks pass. The pipeline deploys without a separate manual approval.

Why does a CI/CD pipeline matter?

A CI/CD pipeline matters because it gives you faster feedback and a consistent way to check changes before release. Automation removes repetitive manual steps, but it does not guarantee that software is defect-free or that a deployment will never fail.

When tests run soon after a change, you can investigate while the code is still fresh in your mind. Small, frequent changes are also easier to review than a large release assembled after a long period of manual integration. GitLab explains how CI/CD automation supports faster delivery and product quality.

A pipeline also makes release steps visible and repeatable. Instead of relying on someone to remember the right commands or server settings, you can write those steps down as configuration. You can then review changes to them alongside your application code.

Detailed CI/CD Pipeline Stages

A CI/CD pipeline usually includes source checks, a build, tests and a release or deployment step. You can add stages to suit your software. Not every project needs a complex pipeline.

Stage What it does Example check
Trigger Starts the workflow after a repository event or manual request. Run checks for a pull request.
Build Installs dependencies and creates an application package. Compile a service or generate a static site.
Test Checks expected behaviour and code quality. Run unit tests and a linter.
Package Stores a versioned build or container image. Tag an image with a commit identifier.
Deploy Publishes the build to a test or production environment. Deploy to staging after checks pass.
Verify Checks the deployed service and reports failures. Run a health check or smoke test.

The pipeline should fail visibly when a required check fails. Decide which failures block a merge or release. Otherwise, automated checks may report problems without changing what anyone does next.

CI/CD Pipeline Examples

Real-world examples of CI/CD pipelines can vary based on project types. For instance, a simple Node.js application may require a straightforward CI/CD pipeline, while a more complex microservices architecture might involve multiple pipelines for different services.

Here are examples of CI/CD configurations:

GitHub Actions Example

The following GitHub Actions example is for a Node.js project that defines test and build scripts in its package.json. GitHub documents workflow syntax and event triggers in its Actions reference.

  1. Create .github/workflows/ci.yml in your repository.
  2. Add the workflow below, and adjust the runtime and commands to match your project.
  3. Push the file, then check the workflow run in the repository's Actions tab.
name: CI

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Check out source
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm

      - name: Install dependencies
        run: npm ci

      - name: Run tests
        run: npm test

      - name: Build application
        run: npm run build

This example validates changes. It does not deploy them. When you are ready to deploy, decide where the application will be published and what approval or verification is required, then add a deployment job. Store production credentials in your CI/CD platform's secrets store rather than committing them to the repository. Limit who can access those credentials, and grant each job only the permissions it needs.

Jenkins Example

A Jenkins CI/CD pipeline defines build, test and deployment stages in a Jenkinsfile stored with your application code. Jenkins runs those stages on an available agent, using shell commands or other steps that suit the project. The official Jenkins Pipeline documentation explains the pipeline model and Jenkinsfile syntax.

This small Declarative Pipeline example runs the same basic Node.js checks:

pipeline {
    agent any

    stages {
        stage('Install') {
            steps {
                sh 'npm ci'
            }
        }

        stage('Test') {
            steps {
                sh 'npm test'
            }
        }

        stage('Build') {
            steps {
                sh 'npm run build'
            }
        }
    }
}

The agent any directive lets Jenkins choose any available agent. You can instead target an agent with the operating system or tools you need. Before you add a production release stage, define its credentials, target environment and approval requirements. The pipeline also needs Jenkins agents with the right runtime and dependencies, so maintain those environments as carefully as the pipeline itself.

Common CI/CD Tools and Their Features

Several tools can help you implement a CI/CD pipeline effectively. Here’s a list of popular CI/CD tools along with their features:

Tool Features When to Use
GitHub Actions Integrated with GitHub, supports custom workflows, and allows for easy CI/CD setup. Ideal for projects hosted on GitHub.
Jenkins Highly customizable, supports a wide range of plugins, and can be configured for complex workflows. Best for teams needing extensive customization.
GitLab CI Integrated with GitLab, offers built-in CI/CD capabilities, and allows for easy configuration. Great for projects on GitLab with a focus on collaboration.
CircleCI Cloud-based, easy to set up, and integrates well with GitHub and Bitbucket. Good for teams looking for a quick setup without managing infrastructure.

Which CI/CD approach suits different projects?

The right pipeline depends on your application, your team and the risk of each deployment. Start with checks that catch likely mistakes. Add release automation once your team can operate it safely.

Project Useful pipeline steps Release approach
Static website Install dependencies, run tests, build site and check generated files. Deploy the build to a preview environment; publish after review.
Web service or API Build, unit tests, integration tests and package the application. Deploy to staging, verify health, then approve production release.
Infrastructure configuration Format and validate configuration, then run a plan or equivalent review. Require review before applying changes to production infrastructure.

For example, a small business website may need only a build check and a staging preview before publishing. An API that handles important business processes may need integration tests, a staged deployment and explicit production approval. Infrastructure changes need particular care, because an automated apply step can change live resources.

What makes a CI/CD pipeline reliable and safe?

A reliable CI/CD pipeline has checks that matter, clear ownership and a recovery plan. Adding more stages does not automatically improve quality. Slow or noisy checks can teach your team to ignore pipeline results.

Keep these practices in mind:

  • Run relevant tests: Use fast checks early, and run broader integration or end-to-end tests where they add real coverage.
  • Protect secrets: Store credentials in the CI/CD platform, limit which workflows can access them, and never print secret values in logs.
  • Use review and approvals: Require review for sensitive code and production deployments when the risk calls for it.
  • Make failures actionable: Show which command failed, and keep useful logs or test reports.
  • Plan for recovery: Keep a way to roll back or redeploy a known-good release, and verify the service after each deployment.

If you are building your DevOps skills, these practical DevOps interview questions and scenarios cover common concepts and operational trade-offs.

Key takeaways

  • A CI/CD pipeline automates the steps that build, test and prepare software changes for release.
  • Continuous Delivery keeps validated software ready to release. Continuous Deployment releases qualifying changes automatically.
  • A useful pipeline gives developers early feedback and makes release steps repeatable. It does not replace testing or operational judgement.
  • Choose pipeline stages based on the project's risks, and protect deployment credentials and production environments.

Start with a small, well-understood pipeline, then extend it as your software and release needs grow. When you plan where to run applications and deployment workloads, Ritik Barnwal's VPS, dedicated server and managed hosting options may suit your infrastructure requirements.

Frequently asked questions

What is a CI/CD pipeline?

A CI/CD pipeline is an automated workflow that enables developers to integrate code changes and deliver them reliably.

What does CI/CD stand for?

CI/CD stands for Continuous Integration and Continuous Delivery or Deployment.

How does a Jenkins CI/CD pipeline work?

A Jenkins CI/CD pipeline defines the stages of building, testing, and deploying applications using a Jenkinsfile.

What is the difference between Continuous Delivery and Continuous Deployment?

Continuous Delivery ensures that code changes are always ready for production, while Continuous Deployment automatically releases changes to production.

Which Node.js version and commands does the GitHub Actions example use?

The GitHub Actions example uses Node.js 22 and runs on pull requests and pushes to the main branch. The workflow checks out source with actions/checkout@v4, sets up Node.js with actions/setup-node@v4, installs dependencies using npm ci, then runs npm test and npm run build.

Does the example CI workflow deploy the application?

No, the example CI workflow does not deploy the application. The GitHub Actions configuration checks out the source, installs dependencies, runs tests and builds the application when a pull request or push targets main. A deployment job must be added separately after choosing a publishing target and defining approval or verification requirements.

What does agent any mean in a Jenkins pipeline?

In a Jenkins pipeline, agent any lets Jenkins choose any available agent to run the pipeline. A Jenkins agent must have the runtime and dependencies the project needs. The Declarative Pipeline example has Install, Test and Build stages, running npm ci, npm test and npm run build.

Comments

Loading comments…

Leave a comment

All articles