Complete guide to deployment automation for AI services — from pipelines to GitOps
CI CI/CD Complete Guide
From the basic concepts of CI/CD through branching strategy, GitHub Actions and Jenkins pipelines, build caching, OIDC-based secret management, supply chain security (SBOM and image signing), Blue-Green and Canary progressive delivery, and GitOps (ArgoCD) — the whole flow for releasing an AI Agent service safely and quickly.
Intermediate
Updated Oct 1, 2026
~13 min read
14 sections
11 code examples
Web IDE lab included
CI
CI/CD Web IDE
Run code in the browser with nothing to install and learn through step-by-step examples.
From the basic concepts of CI/CD through branching strategy, GitHub Actions and Jenkins pipelines, build caching, OIDC-based secret management, supply chain security (SBOM and image signing), Blue-Green and Canary progressive delivery, and GitOps (ArgoCD) — the whole flow for releasing an AI Agent service safely and quickly. Rather than listing concepts, this guide is organized so you can follow the content in the order you have to make decisions on a real project.
Key perspective
Infrastructure / operations
Rather than memorizing install commands, understand the order in which traffic, runtime, observability, and incident response connect.
To make what you read stick, it helps to capture the flow as a picture first. The two diagrams below are reference maps you can keep coming back to while learning CI/CD.
Learning flow
Rendering diagram…
Architecture view
Rendering diagram…
What is CI/CD?
When you first open CI/CD, the big picture matters more than individual commands. This section starts with the problems the concepts ahead were created to solve.
CI (Continuous Integration) is the practice of merging the code of several developers often and building and testing automatically on every merge, to find integration problems early. CD splits into the two stages that follow: Continuous Delivery, which "keeps an artifact ready to deploy at any time", and Continuous Deployment, which "actually deploys to production automatically" with no human approval. The names are similar, but the scope of automation differs.
Rendering diagram…
Term
Scope of automation
Human involvement
CI (Continuous Integration)
Build + automated tests on every commit
Reviewers decide whether to merge
Continuous Delivery
CI + keeping a deploy artifact always ready
A person presses the production deploy button
Continuous Deployment
Delivery + automatic deploy to production when tests pass
None (notified only on failure)
Pipeline design
Here you look at Pipeline design alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
In an AI Agent service, model response quality, RAG retrieval quality, token cost, and response latency all shift together, more so than in an ordinary web service. So CI/CD has to be more than deployment automation: an operational loop that checks code quality, model call stability, prompt regressions, and performance smoke tests together.
Rendering diagram…
Stage
Goal
Typical checks
Install
Pin dependencies and ensure reproducibility
npm ci, uv sync, lockfile check
Build
Catch frontend/backend build failures early
npm run build, Docker build
Test
Verify the core API and Agent flows
unit test, API contract, RAG sample eval
Security
Block secret leaks and vulnerable images
secret scan, npm audit, image scan
Deploy
Roll out to production after checking staging
smoke test, health check, rollback point
Branching strategy & triggers
Here you look at Branching strategy & triggers alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
The branching strategy is what decides "when CI runs and when a deployment happens". The more long-lived branches there are, the bigger the conflicts and integration problems at merge time, so most teams are converging on Trunk-Based Development, where feature branches live and die within a day or two.
Rendering diagram…
Strategy
Characteristics
Good fit
Trunk-Based
Feature branches merge to main within a day or two; unfinished features hidden behind feature flags
Fast release cycles; most teams with mature CI/CD (recommended)
GitHub Flow
main + feature branches, deploy as soon as the PR merges
Simple web services, small teams
GitFlow
Several long-lived branches: main/develop/release/hotfix and so on
Packaged software with a fixed release cycle (overkill these days)
A basic GitHub Actions workflow
Here you look at A basic GitHub Actions workflow alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
On PRs, only build and test run; the Docker image is built and deployed when the change merges to the main branch. An AI Agent project needs model API keys, a DB URL, and vector DB connection details, so store them separately in GitHub Secrets.
Here you look at The Jenkins Pipeline approach alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Jenkins is still powerful in organizations that need an internal network, dedicated build servers, air-gapped deployment, or approval steps. Keeping the Jenkinsfile in the repository lets you manage the build procedure as code, and Credentials can hold model API keys and registry tokens safely.
JenkinsfileGROOVY
pipeline { agent any environment { NODE_VERSION = '22' IMAGE_NAME = 'registry.example.com/aidevops-agent' IMAGE_TAG = "${env.GIT_COMMIT}" } options { timestamps() disableConcurrentBuilds() buildDiscarder(logRotator(numToKeepStr: '20')) } stages { stage('Checkout') { steps { checkout scm } } stage('Install') { steps { sh 'node --version' sh 'npm ci' } } stage('Build') { steps { sh 'npm run build' } } stage('Test') { steps { sh 'npm test -- --runInBand || true' sh 'bash scripts/ci-smoke.sh' } } stage('Docker Build') { steps { sh 'docker build -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest .' } } stage('Docker Push') { when { branch 'main' } steps { withCredentials([usernamePassword( credentialsId: 'container-registry', usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_PASSWORD' )]) { sh 'echo $REGISTRY_PASSWORD | docker login registry.example.com -u $REGISTRY_USER --password-stdin' sh 'docker push $IMAGE_NAME:$IMAGE_TAG' sh 'docker push $IMAGE_NAME:latest' } } } stage('Deploy Staging') { when { branch 'main' } steps { sh 'ssh deploy@staging "cd /opt/aidevops-agent && docker compose pull && docker compose up -d"' sh 'BASE_URL=https://staging.example.com bash scripts/ci-smoke.sh' } } stage('Approve Production') { when { branch 'main' } steps { input message: 'Deploy to production?', ok: 'Deploy' } } stage('Deploy Production') { when { branch 'main' } steps { sh 'ssh deploy@prod "cd /opt/aidevops-agent && docker compose pull && docker compose up -d"' sh 'BASE_URL=https://www.aidevops.us bash scripts/ci-smoke.sh' } } } post { failure { echo 'Pipeline failed. Check build logs and rollback if production deploy started.' } always { sh 'docker image prune -f || true' } }}
Component
Recommended approach
Caution
Agent
A Jenkins node that can run Docker
Check Docker socket permissions and build isolation
Credentials
Jenkins Credentials Binding
Never print API keys to the logs
Stages
Install, Build, Test, Image, Deploy
Separate the failure point of each stage clearly
Approval
Approve the production deploy with an input step
Approve after the staging smoke test
Rollback
The previous image tag or kubectl rollout undo
Record the current tag before deploying
Caching & build speed optimization
Here you look at Caching & build speed optimization alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
When the CI pipeline gets slow, developers start on something else while waiting for review, and the cost of context switching grows accordingly. Simply caching dependency installs and Docker layers and splitting tests to run in parallel often brings a pipeline that took 5-10 minutes down to the 1-2 minute range.
jobs: test: strategy: matrix: shard: [1, 2, 3, 4] # split the tests into 4 and run them at the same time runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 22 cache: npm # automatic caching keyed on the package-lock.json hash - run: npm ci - run: npm test -- --shard=${{ matrix.shard }}/4
Cache scope
Problem
Fix
Key too broad (e.g. just the branch name)
Keeps using a stale cache even after dependencies change — causes subtle bugs
Always include the lockfile hash in the cache key
Key too narrow (e.g. the commit SHA)
The cache differs on every commit, so in effect nothing is reused
Include only values that really affect cache validity, such as the lockfile, OS, and language version
Building and deploying Docker images
Here you look at Building and deploying Docker images alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
For production deployment, pushing a Docker image verified in CI to a registry and having the server pull that tag is more reliable than building the source code directly on the server. Using the commit SHA as the tag makes it easy to trace which code was deployed.
Here you look at Secret management & OIDC alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
If a long-lived access key such as AWS_ACCESS_KEY_ID sits in GitHub Secrets, then once it leaks it can keep being abused until you expire it. With OIDC (OpenID Connect) federation, the CI job gets short-lived credentials straight from the cloud provider, valid only for the moment it runs, so there is no cloud key to store in GitHub Secrets in the first place.
Rendering diagram…
.github/workflows/deploy.ymlYAML
permissions: id-token: write # required to issue the OIDC token contents: readjobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: arn:aws:iam::123456789012:role/github-actions-deployer aws-region: us-east-1 # temporary credentials are issued here, with no AWS_ACCESS_KEY_ID/SECRET - run: aws ecs update-service --cluster prod --service api --force-new-deployment
Method
Risk if leaked
Expiry
Long-lived access key
Can be abused without limit until it expires
Permanent unless rotated by hand
Short-lived OIDC token
Usually already expired and cannot be reused
Typically 15 minutes to 1 hour
Quality gates for AI Agents
Here you look at Quality gates for AI Agents alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
In an AI service, answer quality can get worse even when the build succeeds. At a minimum, check a fixed question set, RAG retrieval samples, a response time threshold, and a cost threshold in CI.
Here you look at Supply chain security — SBOM & image signing alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Even when the image itself has no vulnerabilities, that does not stop a supply chain attack in which a dependency is quietly tampered with during the build, or an unverified image is deployed as-is. The core of supply chain security is recording exactly which packages at which versions are in the image with an SBOM (Software Bill of Materials), and signing the image so that just before deployment you can verify "was this image really built by our CI?".
permissions: contents: read packages: write id-token: write # required for keyless signingsteps: - uses: docker/build-push-action@v6 id: build with: push: true tags: ${{ env.IMAGE_NAME }}:${{ github.sha }} sbom: true # attach the SBOM to the image - uses: sigstore/cosign-installer@v3 - name: Sign the image (keyless — signed with the GitHub OIDC identity) run: cosign sign --yes ${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
BASH
# Verify the signature right before deploying, on the deploy server/CD pipelinecosign verify \ --certificate-identity-regexp "https://github.com/myorg/myrepo/.*" \ --certificate-oidc-issuer https://token.actions.githubusercontent.com \ ghcr.io/myorg/myapp@sha256:abc123...# On verification failure the exit code is non-zero, so the CD script can stop the deploy right there
Tool/concept
Role
SBOM
The list of every package and version in the image — lets you find affected images at once when a new CVE is announced
cosign sign (keyless)
Signs the image with the GitHub OIDC identity — no private key to manage separately
cosign verify
Confirms before deployment that the signature came from a trusted CI pipeline
Here you look at Progressive delivery strategies (Blue-Green, Canary) alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Switching 100% of traffic to a new version at once means every user is affected at the same time if something is wrong. Blue-Green and Canary both implement the same goal — "expose the new version to a few first, and widen it gradually if all is well" — in different ways.
Rendering diagram…
Strategy
How it switches
Pros
Cons
Blue-Green
Switches traffic all at once to a verified new environment
Instant rollback (just point the traffic back)
Needs double the infrastructure resources for a moment
Canary
Sends only part of the traffic to the new version and raises the share gradually
Small-scale verification on real traffic; small blast radius if something is wrong
Compatibility (DB schema and so on) must be managed while both versions coexist
Rolling (for reference)
The approach covered in the docker/kubernetes guides — replaces instances one at a time
Works with no extra resources
New and old versions both take traffic during the switch
Deployment and rollback
Here you look at Deployment and rollback alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
For production deployment, being reversible matters more than being fast at all costs. Record the current image tag before deploying, and if the health check of the new image fails, go back to the previous tag at once.
scripts/deploy.shBASH
#!/usr/bin/env bashset -euo pipefailAPP_DIR="/opt/aidevops-agent"IMAGE="ghcr.io/org/aidevops-agent:${GITHUB_SHA:-latest}"ssh "$DEPLOY_USER@$DEPLOY_HOST" <<EOF set -euo pipefail cd "$APP_DIR" docker compose ps docker compose pull docker compose up -d sleep 10 curl -fsS http://localhost:3000/healthEOF# If you use Kubernetes:# kubectl set image deployment/aidevops-agent app=$IMAGE# kubectl rollout status deployment/aidevops-agent# kubectl rollout undo deployment/aidevops-agent
IaC pipelines — Terraform & Ansible
Here you look at IaC pipelines — Terraform & Ansible alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Where CI/CD builds and deploys application code, Terraform and Ansible manage as code the infrastructure that application runs on. Terraform is a tool for provisioning resources such as a VPC, EKS, or RDS by declaring "what state the infrastructure should be in", and Ansible is a tool that brings existing servers into line over SSH with configuration such as installing packages and distributing config files — both fit naturally into CI/CD as separate pipeline stages.
Procedural (describes the sequence of tasks to perform)
Main use
Provisioning cloud resources (VPC, EKS, RDS, and so on)
Automating configuration and deployment on existing servers
State management
Tracks the current infrastructure state in a state file
No state file — checks the target servers directly on every run
GitOps (ArgoCD)
Here you look at GitOps (ArgoCD) alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.
Every approach so far is a "push-based" deployment, in which the CI pipeline accesses the cluster directly and runs kubectl apply or docker compose up. GitOps is the reverse, a "pull-based" approach: you declare the manifests in a Git repository as "the state this cluster should reach", and an agent running inside the cluster (ArgoCD, Flux) continuously compares that state with the real cluster and brings it into line by itself.
Rendering diagram…
argocd-application.yamlYAML
apiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: myapp namespace: argocdspec: project: default source: repoURL: https://github.com/myorg/myapp-manifests.git targetRevision: main path: overlays/production destination: server: https://kubernetes.default.svc namespace: production syncPolicy: automated: prune: true # resources deleted from Git are deleted from the cluster automatically too selfHeal: true # restores the Git state automatically even if someone changes things by hand with kubectl
Aspect
Push-based CI/CD
GitOps (pull-based)
Cluster access credentials
The CI system must hold access rights to the cluster
No access from outside the cluster needed — smaller attack surface
Deployment history
You have to check the CI logs separately
The Git commit history is the deployment history
Rollback
Re-run the previous deployment script
A single git revert syncs back to the previous state automatically
Configuration drift
A manual kubectl change by someone just stays there
selfHeal reverts anything that differs from Git automatically
CI/CD: frequently asked questions
What is the difference between CI and CD?
CI (continuous integration) builds and tests the code automatically on every push so problems are found early. CD means either getting that output into a deployable state (continuous delivery) or deploying it all the way to production automatically (continuous deployment). Teams usually set up CI first, automate deployment up to staging, and keep an approval step before production.
Should I choose GitHub Actions or Jenkins?
If your code is on GitHub and you do not want to run a separate server, GitHub Actions is the easy start. Jenkins can fit better when jobs must run inside a private network, when you need fine-grained control through plugins, and when people are already available to operate it. GitHub Actions can also run jobs on your own servers with self-hosted runners.
How is GitOps different from traditional CI/CD?
In the traditional approach the pipeline runs the deploy command and pushes changes into the cluster. With GitOps you declare the desired state in a Git repository, and a tool such as Argo CD or Flux runs inside the cluster, compares Git with the actual state, and reconciles them. Deployment history is the Git history, rolling back is reverting a commit, and the pipeline needs less access to the cluster.
How do I manage passwords and API keys in a pipeline?
Do not write them in the repository. Store them in the CI tool's secret store and inject them as environment variables. Keep the values out of logs, scope permissions to what is needed, and rotate them regularly. For cloud deployments, getting short-lived credentials through OIDC is safer than long-lived keys.