Prompt
How do I build a CI pipeline that runs build test package and deploy steps?
Latest observation
Here’s a practical way to build a CI/CD pipeline that runs build → test → package → deploy.
1) Define the stages
A typical pipeline looks like this:
-
Build
Compile the app, install dependencies, and produce build artifacts. -
Test
Run unit tests, integration tests, linting, and possibly security scans. -
Package
Create a deployable artifact:- Docker image
- ZIP/JAR/WAR
- npm package
- Python wheel, etc.
-
Deploy
Push the artifact to staging/production or a deployment target.
2) Choose a CI/CD tool
Common options:
- GitHub Actions
- GitLab CI/CD
- Jenkins
- CircleCI
- Azure DevOps
- Bitbucket Pipelines
If you want something simple and modern, GitHub Actions is a good default.
3) Make the pipeline fail fast
A good pipeline should:
- run build first
- stop immediately if build fails
- run tests only if build passes
- package only if tests pass
- deploy only if package succeeds
This saves time and prevents bad releases.
4) Store configuration securely
Use:
- secrets for API keys, cloud credentials, and tokens
- environment variables for non-sensitive config
- separate environments like
dev,staging, andprod
Never hardcode credentials in the repo.
5) Example workflow
Here’s a simple GitHub Actions example for a Node.js app:
name: CI-CD Pipeline
on:
push:
branches: [ "main" ]
pull_request:
jobs:
build_test_package:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Package
run: tar -czf app.tar.gz dist package.json node_modules
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: app-package
path: app.tar.gz
deploy:
needs: build_test_package
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: app-package
- name: Deploy
run: ./deploy.sh
6) Best practices
- Use separate jobs/stages for build, test, package, and deploy
- Cache dependencies to speed up runs
- Run tests in parallel when possible
- Use artifacts to pass build outputs between stages
- Deploy only from protected branches like
main - Add approval gates for production
- Version your artifacts
- Add notifications for failures/successes
- Use blue-green or canary deploys for safer releases
7) Recommended pipeline structure
A solid production pipeline often looks like this:
- Lint
- Build
- Unit tests
- Integration tests
- Security scan
- Package artifact
- Deploy to staging
- Smoke test
- Manual approval
- Deploy to production
8) If you deploy with Docker
Then the package step usually becomes:
- build a Docker image
- tag it with commit SHA or version
- push to a registry
- deploy that image to Kubernetes, ECS, Cloud Run, etc.
Example commands:
docker build -t myapp:${GITHUB_SHA} .
docker tag myapp:${GITHUB_SHA} myregistry/myapp:${GITHUB_SHA}
docker push myregistry/myapp:${GITHUB_SHA}
9) What a good pipeline should output
At the end, you want:
- a validated build
- test results
- a versioned artifact
- a deployed release
- logs and traceability for audit/debugging
If you want, I can give you a complete pipeline example for one of these tools:
- GitHub Actions
- GitLab CI
- Jenkins
- Azure DevOps
And I can tailor it for Node.js, Python, Java, Docker, or .NET.