Pipeline Generation
Create complete CI/CD configurations from descriptions
Ta treść nie jest jeszcze dostępna w Twoim języku.
Modern software development demands automated pipelines that build, test, and deploy code reliably. This lesson shows how Cursor IDE’s AI capabilities can help you design, implement, and maintain sophisticated CI/CD workflows that would typically require DevOps expertise.
Cursor’s AI understands popular CI/CD platforms, their configuration languages, and best practices. It can generate pipeline configurations, debug failures, and suggest optimizations based on your project’s needs.
Pipeline Generation
Create complete CI/CD configurations from descriptions
Test Automation
Generate comprehensive test suites and strategies
Deployment Scripts
Build deployment automation for any platform
Monitoring Setup
Configure pipeline monitoring and alerting
# Agent prompt:"Create a GitHub Actions workflow for a Node.js app with:- Build and test on multiple Node versions- Code coverage reporting- Docker image building- Deployment to AWS ECS- Slack notifications"
# Agent prompt:"Generate GitLab CI pipeline with:- Parallel test execution- Docker layer caching- Kubernetes deployment- Environment-specific configs- Manual approval for production"
// Agent prompt:"Create Jenkinsfile with:- Declarative pipeline syntax- Docker agents for builds- Blue Ocean compatible- Shared libraries usage- Post-build notifications"
Let’s build a production-ready CI/CD pipeline for a full-stack application:
Create the workflow structure
@.github/workflowsCreate a comprehensive GitHub Actions workflow:- Trigger on push to main and PRs- Run linting, testing, and security checks- Build Docker images with caching- Deploy to staging automatically- Deploy to production with approval
Cursor generates the complete workflow
name: CI/CD Pipeline
on: push: branches: [main, develop] pull_request: branches: [main]
env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }}
jobs: lint-and-test: runs-on: ubuntu-latest strategy: matrix: node-version: [18.x, 20.x]
steps: - uses: actions/checkout@v4
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'npm'
- name: Install dependencies run: npm ci
- name: Run linting run: npm run lint
- name: Run tests run: npm test -- --coverage
- name: Upload coverage uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }}
Add security scanning
security: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Run security audit run: npm audit --production
- name: Run SAST scan uses: github/super-linter@v5 env: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-push: needs: [lint-and-test, security] runs-on: ubuntu-latest permissions: contents: read packages: write
steps: - uses: actions/checkout@v4
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} type=sha,prefix={{branch}}-
- name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max
deploy-staging: needs: build-and-push runs-on: ubuntu-latest environment: staging
steps: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: us-east-1
- name: Deploy to ECS run: | aws ecs update-service \ --cluster staging-cluster \ --service my-app-service \ --force-new-deployment
deploy-k8s: needs: build-and-push runs-on: ubuntu-latest
steps: - uses: actions/checkout@v4
- name: Setup kubectl uses: azure/setup-kubectl@v3
- name: Deploy to Kubernetes run: | kubectl set image deployment/my-app \ my-app=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} kubectl rollout status deployment/my-app
Ask Cursor to implement complex matrix strategies:
Create a matrix build that tests:- Multiple OS (Ubuntu, Windows, macOS)- Multiple Node versions (16, 18, 20)- Multiple database versions (PostgreSQL 12, 13, 14)- Skip incompatible combinations
test-suite: runs-on: ubuntu-latest strategy: matrix: test-group: [unit, integration, e2e]
steps: - name: Run ${{ matrix.test-group }} tests run: npm run test:${{ matrix.test-group }}
deploy-production: if: github.ref == 'refs/heads/main' && github.event_name == 'push' needs: [deploy-staging] environment: name: production url: https://app.example.com
steps: - name: Wait for approval uses: trstringer/manual-approval@v1 with: approvers: tech-lead,devops-team
Use Cursor to generate a complete testing strategy:
Unit Tests
Generate unit tests with:- 80% code coverage minimum- Mock external dependencies- Test edge cases- Performance benchmarks
Integration Tests
Create integration tests:- Test API endpoints- Database operations- External service integrations- Use test containers
End-to-End Tests
Implement E2E tests:- Use Playwright/Cypress- Test critical user flows- Cross-browser testing- Visual regression tests
Implement blue-green deployment in GitHub Actions:1. Deploy to green environment2. Run smoke tests3. Switch load balancer to green4. Keep blue for rollback5. Clean up old blue after success
canary-deploy: steps: - name: Deploy canary run: | kubectl set image deployment/my-app-canary \ my-app=${{ env.NEW_IMAGE }}
- name: Monitor metrics run: | ./scripts/check-canary-metrics.sh
- name: Gradual rollout run: | for percent in 10 25 50 100; do kubectl patch deployment my-app \ -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge":"'$percent'%"}}}}' sleep 300 ./scripts/check-health.sh || exit 1 done
Integrate feature flags with CI/CD:- Use LaunchDarkly/Unleash- Deploy code with flags off- Gradually enable features- Monitor metrics per feature- Automatic rollback on errors
Implement caching
- name: Cache dependencies uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Use Docker layer caching
- name: Build with cache uses: docker/build-push-action@v5 with: cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
Parallelize independent jobs
jobs: test: # Runs immediately security-scan: # Runs in parallel with test build: needs: [test, security-scan] # Waits for both
Ask Cursor to optimize for CI/CD costs:
Optimize GitHub Actions for cost:- Use larger runners only when needed- Implement job timeouts- Skip unchanged components- Use conditional workflows- Archive old artifacts
- name: Send metrics to DataDog if: always() run: | curl -X POST "https://api.datadoghq.com/api/v1/series" \ -H "Content-Type: application/json" \ -H "DD-API-KEY: ${{ secrets.DD_API_KEY }}" \ -d @- <<EOF { "series": [{ "metric": "ci.pipeline.duration", "points": [[${{ steps.timer.outputs.time }}, ${{ steps.timer.outputs.duration }}]], "tags": ["pipeline:${{ github.workflow }}", "status:${{ job.status }}"] }] } EOF
- name: Notify Slack if: failure() uses: slackapi/slack-github-action@v1 with: payload: | { "text": "Deployment failed!", "blocks": [{ "type": "section", "text": { "type": "mrkdwn", "text": "❌ *${{ github.workflow }}* failed\n${{ github.event.pull_request.html_url || github.event.head_commit.url }}" } }] } env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Send email notification if: failure() uses: dawidd6/action-send-mail@v3 with: server_address: smtp.gmail.com server_port: 465 username: ${{ secrets.EMAIL_USERNAME }} password: ${{ secrets.EMAIL_PASSWORD }} subject: Build Failed - ${{ github.repository }} body: | Build failed for ${{ github.workflow }} Commit: ${{ github.sha }} Author: ${{ github.actor }}
Implement secure secrets handling:1. Use GitHub Secrets for sensitive data2. Rotate secrets regularly3. Use OIDC for cloud authentication4. Implement least-privilege access5. Audit secret usage
- name: Generate SBOM uses: anchore/sbom-action@v0 with: output-file: sbom.spdx.json
- name: Sign container image uses: sigstore/cosign-installer@v3 run: | cosign sign --yes \ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
Use Cursor to diagnose pipeline failures:
My GitHub Actions workflow is failing with "Error: Process completed with exit code 1"Help me debug by:1. Adding detailed logging2. Checking environment variables3. Validating file permissions4. Testing locally with act
# Test GitHub Actions locallyact -j build --secret-file .env.secrets
# Debug specific jobact -j test --verbose
# Use specific Docker imageact -j deploy --platform ubuntu-latest=nektos/act-environments-ubuntu:18.04
Create CI/CD for a monorepo with:- Detect changed packages- Run tests only for affected code- Build and deploy changed services- Shared dependency caching- Parallel execution per package
ios-build: runs-on: macos-latest steps: - uses: actions/checkout@v4
- name: Setup Xcode uses: maxim-lobanov/setup-xcode@v1 with: xcode-version: latest-stable
- name: Build and test run: | xcodebuild test \ -scheme MyApp \ -destination 'platform=iOS Simulator,name=iPhone 14'
- name: Upload to TestFlight run: | xcrun altool --upload-app \ -f MyApp.ipa \ -u ${{ secrets.APPLE_ID }} \ -p ${{ secrets.APP_PASSWORD }}
Keep all pipeline configurations in your repository for traceability and rollback capabilities.
Use Cursor to create reusable workflow templates and composite actions.
Order jobs to catch failures early and save compute resources.
Ask Cursor to generate documentation for complex pipeline logic.
Track pipeline metrics, costs, and performance trends.
Key metrics to track:
After mastering CI/CD with Cursor:
Remember: Cursor doesn’t just help you write pipeline configurations—it helps you understand CI/CD patterns and best practices that create reliable, efficient software delivery systems.