devops

CI/CD Pipeline: What It Is and How to Set One Up for AI Products

An automated workflow for continuously integrating code changes, running tests, and deploying software to production with minimal manual intervention.

A CI/CD pipeline is the backbone of any team that ships software reliably and repeatedly. CI stands for continuous integration: every code change is automatically tested and merged into a shared branch. CD covers either continuous delivery, where software is always in a releasable state, or continuous deployment, where passing builds are automatically pushed to production. These practices have become the standard delivery model for SaaS and AI products globally, reducing deployment risk by making releases smaller and more frequent rather than large and infrequent. For UK AI and SaaS teams, a working CI/CD pipeline is also relevant to ISO 27001 change management controls and SOC 2 audit requirements, both of which expect documented and reviewable processes for pushing code to production rather than ad hoc deployments from developer laptops. For AI products specifically, a well-configured pipeline is the difference between shipping confidently twice a day and deploying nervously once a month while wondering whether untested code might break a production LLM integration. GitHub Actions is the most practical starting point for most UK AI startups already using GitHub, integrating natively with Vercel for zero-configuration deployments on merge to main. Environment variable management for LLM API keys across development, staging, and production environments is a common source of pipeline misconfiguration that a properly structured pipeline prevents. SpeedMVPs, based in Hemel Hempstead, delivers AI MVPs in 2 to 3 weeks at a GBP 8,000 fixed price with full code ownership, and includes a working CI/CD pipeline configured and documented as part of every project deliverable. This guide explains the pipeline components, how to set one up for a Next.js or Node.js AI product, and the specific considerations that apply when your product makes LLM API calls in production.

The Core Components of a CI/CD Pipeline

A CI/CD pipeline is a sequence of automated stages that run whenever a developer pushes code. The typical stages are source control trigger, build, test, security scan, and deploy. The source control trigger fires when a pull request is opened or merged into a protected branch. The build stage compiles the application, resolves dependencies, and produces an artifact, a container image or deployment package, that is identical to what will run in production. The test stage runs unit tests, integration tests, and any end-to-end tests in the pipeline. A security scan stage checks dependencies for known vulnerabilities and can apply static analysis to flag common security issues in code. The deploy stage takes the build artifact and pushes it to the target environment, whether a staging environment on pull request or production on merge to main. The key property of a good pipeline is that every stage is deterministic and fast. If the pipeline takes 45 minutes to run, developers stop waiting for it and start merging without full test coverage. A well-tuned pipeline for an AI Next.js product should complete in under ten minutes.

GitHub Actions for AI SaaS Products

GitHub Actions is the most practical starting point for most UK AI startups because it integrates natively with GitHub where code already lives. A workflow file in .github/workflows defines the pipeline as YAML, which version-controls your pipeline configuration alongside your application code. For a typical Next.js AI product, the CI workflow runs on every pull request: install dependencies, run TypeScript type checking, run ESLint, run Jest unit tests, and build the application to verify no build errors exist. The CD workflow runs on merge to main: build the production Docker image, push it to a container registry such as GitHub Container Registry or AWS ECR, and trigger a deployment to your hosting platform. For Vercel-hosted products, Vercel's GitHub integration handles deployment automatically on push to main, eliminating the need for a custom deploy step. Environment variables containing API keys for OpenAI, Anthropic, or other LLM providers should be stored as GitHub Actions secrets, never hardcoded in workflow files.

Testing AI Features in a Pipeline

Testing AI features in a CI/CD pipeline requires decisions about which tests run in the pipeline and which run separately. Unit tests for non-AI application logic should always run in the pipeline on every pull request. They are fast, deterministic, and provide immediate feedback. Integration tests that call real LLM APIs should generally not run in the standard PR pipeline because they are slow, non-deterministic, cost money per run, and can fail for reasons unrelated to your code change such as provider outages or rate limits. The pragmatic approach is to mock LLM API calls in unit and integration tests for the pipeline, and maintain a separate scheduled evaluation suite that runs real LLM calls against a fixed set of test cases on a nightly or weekly basis. This evaluation suite tests that prompt templates still produce outputs meeting quality thresholds, which is the AI equivalent of regression testing. Tools such as LangSmith, PromptLayer, and Braintrust are built for this kind of LLM evaluation workflow outside the standard CI pipeline.

Environment Management and Secrets

A CI/CD pipeline manages code deployments across multiple environments: development, staging or preview, and production. Each environment needs its own set of environment variables and should be logically isolated. For AI products, this means separate LLM API keys per environment, separate database connections, and where possible separate LLM usage budgets with alerts configured so a runaway test suite does not exhaust your production API quota. Secrets management must be handled carefully. API keys for OpenAI, Anthropic, database connection strings, and third-party service credentials should never appear in source code, in Dockerfiles, or in pipeline logs. Use GitHub Actions secrets for CI/CD-level secrets, your hosting platform's environment variable management for production secrets, and a secrets manager such as AWS Secrets Manager or HashiCorp Vault for enterprise-grade rotation and audit logging. Review your pipeline logs regularly to verify that no secrets are being accidentally printed to output, which is a common misconfiguration especially when debugging failing builds.

Deployment Strategies in the Pipeline

The deploy stage of a CI/CD pipeline can implement different deployment strategies depending on your risk tolerance and infrastructure. For most early-stage AI products on Vercel or similar PaaS platforms, automatic deployment on merge to main is the right default. Vercel creates immutable deployment URLs for each build, making rollback as simple as promoting a previous deployment to production. For containerised products on AWS ECS, GCP Cloud Run, or Kubernetes, the pipeline can implement blue-green or canary deployment strategies as part of the deploy stage. A canary deployment sends a small percentage of traffic to the new version and monitors error rates before promoting it fully. Blue-green deployment maintains two complete environments and switches traffic atomically. Both strategies require health check configuration in the pipeline so the deploy stage can detect a bad deployment before it reaches all users. The pipeline's deploy stage should always verify that the newly deployed version is healthy before completing, never just assume that a successful container push means a successful deployment.

Pipeline Configuration for SpeedMVPs Projects

At SpeedMVPs, every AI MVP is delivered with a working CI/CD pipeline configured from the first sprint. For Next.js products deployed on Vercel, the pipeline uses GitHub Actions for CI (type checking, linting, unit tests) and Vercel's native GitHub integration for CD. For containerised products, we configure GitHub Actions for the full CI and CD workflow including Docker build, push to ECR or GCR, and deployment to the target platform. Pipeline configuration is part of the deliverable alongside application code, which means clients inherit a working deployment workflow rather than a codebase that requires additional DevOps work before it can be deployed reliably. Environment variable documentation is included in the project handover so that any developer can understand what secrets are needed and where they are managed.

Frequently Asked Questions

How long should a CI/CD pipeline take for an AI Next.js product?+

For a typical AI Next.js product, a well-configured CI pipeline should complete in five to ten minutes. TypeScript type checking and ESLint run in parallel and typically take one to two minutes. Jest unit tests for a mid-size codebase run in two to four minutes. The Next.js build takes two to four minutes. If your pipeline consistently runs longer than ten minutes, investigate which stages are slowest: dependency installation (fix with caching), test suite size (parallelise or split), or build time (use Next.js incremental builds and Docker layer caching).

Should we run LLM API calls in our CI pipeline tests?+

Generally no. Real LLM API calls in CI tests are slow, non-deterministic, cost money on every run, and fail for reasons outside your control such as provider outages. Mock LLM API responses in your unit and integration tests for CI. Run real LLM evaluation tests on a separate scheduled cadence, nightly or weekly, using a dedicated evaluation framework. This gives you fast feedback on application logic in CI and separate signal on LLM quality that does not block developer workflows.

What is the difference between CI and CD?+

CI, continuous integration, is the practice of automatically building and testing code whenever changes are pushed to a shared repository. The goal is to detect integration problems early. CD can mean continuous delivery, where every passing build is packaged and ready to deploy with a manual approval step, or continuous deployment, where every passing build is automatically deployed to production without human intervention. Most early-stage AI startups should start with continuous deployment to production on merge to main, removing the friction of manual deployments while maintaining quality gates through automated testing.

How do we handle database migrations in a CI/CD pipeline?+

Database migrations should run as part of the deploy stage, after the new application version is deployed but configured to still be able to read from the old schema if the migration has not yet run. The safest approach is to make migrations backwards-compatible, meaning the new code works with both the old and new schema, run the migration, then deploy a follow-up that removes any backwards-compatibility shims. Tools such as Prisma Migrate and Flyway integrate naturally into CI/CD pipelines and provide migration history tracking that is essential for managing schema changes across multiple environments.

Can we set up a CI/CD pipeline on a new project in a day?+

Yes, for a Vercel-hosted Next.js project using GitHub. Vercel's GitHub integration provides automatic deployments on push with zero configuration. Adding a GitHub Actions CI workflow for type checking, linting, and unit tests takes two to four hours for a developer familiar with the tooling. The result is a working pipeline that blocks merges on failing tests and deploys automatically on merge to main. More complex pipelines with containerisation, staging environments, and canary deployments take longer, but the core CI/CD loop is achievable on day one of a new project.

Every SpeedMVPs project is delivered with a working CI/CD pipeline configured and documented. Get a free consultation at speedmvps.co.uk

Get a Free Quote