Building CI/CD Pipelines with n8n

devops ci-cd automation

n8n is typically marketed for business automation—Slack notifications, CRM updates, email workflows. But it’s also surprisingly capable for CI/CD and developer workflows.

Why n8n for CI/CD?

GitHub Actions and GitLab CI are excellent but:

n8n offers:

Basic Deployment Pipeline

Webhook (Git Push) → Build → Test → Deploy → Notify

Setting Up the Webhook

  1. Create an n8n webhook node
  2. Copy the webhook URL
  3. Add to GitHub/GitLab as a webhook
// Incoming webhook payload (GitHub)
{
  "ref": "refs/heads/main",
  "repository": {
    "name": "my-app",
    "clone_url": "https://github.com/user/my-app.git"
  },
  "commits": [...]
}

Filtering Branches

Use an IF node:

// Condition
{{ $json["ref"] === "refs/heads/main" }}

Only process pushes to main.

Running Build Commands

SSH node or Execute Command node:

cd /var/www/my-app
git pull origin main
npm install
npm run build

Test Execution

npm test

Check exit code in next node:

{{ $json["exitCode"] === 0 }}

Conditional Deployment

If tests pass → deploy. If tests fail → notify.

        ┌─ Tests Pass ──→ Deploy ──→ Success Notification

Tests ──┤

        └─ Tests Fail ──→ Failure Notification

Advanced: Docker Builds

docker build -t my-app:$GIT_SHA .
docker push registry.example.com/my-app:$GIT_SHA

# Update Kubernetes
kubectl set image deployment/my-app my-app=registry.example.com/my-app:$GIT_SHA

Integration Examples

Slack Notifications

// Workflow: Build completed
// Slack message:
{
  "blocks": [
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "✅ *Build Successful*\nCommit: {{ $('Webhook').item.json.commits[0].message }}"
      }
    }
  ]
}

GitHub Status Checks

Use the GitHub node to update commit statuses:

{
  "owner": "username",
  "repo": "my-app",
  "sha": "{{ $json.after }}",
  "state": "success",
  "context": "n8n-ci",
  "description": "All tests passed"
}

Jira Integration

Auto-transition tickets when deploys complete:

// When deploy succeeds
// Jira: Transition issue to "Done"
{
  "issueKey": "PROJECT-123",
  "transition": {
    "id": "31"  // "Done" transition ID
  }
}

Scheduled Jobs

n8n excels at scheduled tasks:

Daily Database Backup

Schedule (2am daily) → SSH Backup → Upload to S3 → Notify

Weekly Dependency Check

Schedule (Monday 9am) → Run npm audit → Parse results → 
  → If vulnerabilities: Create Jira ticket + Slack alert
  → If clean: Log success

Certificate Expiry Monitoring

Schedule (daily) → Check SSL certs → If expiring < 30 days → Alert

Debugging Advantages

n8n provides visual execution history:

Compare to scrolling through CI logs.

When n8n Works Well

✅ Multi-platform integration (not just git) ✅ Complex conditional logic ✅ Long-running workflows with human approval ✅ Visual debugging needs ✅ Non-developer teams managing workflows

When Traditional CI is Better

❌ Heavy parallel builds ❌ Matrix testing ❌ Deep VCS integration (protected branches, required checks) ❌ Massive workflow scale

Self-Hosting Setup

# docker-compose.yml
version: '3'
services:
  n8n:
    image: n8nio/n8n
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=admin
      - N8N_BASIC_AUTH_PASSWORD=secure-password
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Security Considerations

Real-World Workflow

1. GitHub webhook received
2. IF: main branch?
   → No: Exit
   → Yes: Continue
3. SSH: Pull code, run tests
4. IF: Tests pass?
   → No: Slack failure notification + GitHub status fail
   → Yes: Continue
5. SSH: Deploy to staging
6. Wait: 5 minutes (smoke test time)
7. HTTP: Check health endpoint
8. IF: Healthy?
   → No: Rollback + Alert
   → Yes: Deploy to production
9. Slack: Success notification
10. Jira: Update ticket status

All visual. All auditable.

Final Thoughts

n8n isn’t replacing GitHub Actions. But for cross-platform automation, complex conditional flows, and visual debugging, it’s a powerful complement.

Start with notifications and monitoring. Expand into deployment as you gain confidence.


Automation shouldn’t require a PhD in YAML.

All posts