Contents

Building a CI/CD Pipeline Trigger with n8n

Triggering CI/CD pipelines from external events is a common DevOps requirement. Whether you need to deploy after a Slack command, trigger builds from a custom dashboard, or orchestrate multi-repo deployments, n8n provides a flexible solution.

This tutorial shows you how to build a workflow that triggers GitHub Actions or GitLab CI pipelines from any webhook source.

Download the Workflow
Get the ready-to-use workflow from our n8n Workflow Gallery.

Before starting, ensure you have:

  • An n8n instance (self-hosted or n8n Cloud)
  • GitHub Personal Access Token with repo and workflow permissions
  • Or GitLab API token with api scope
  • A repository with existing CI/CD workflows

The workflow accepts webhook requests and routes them to either GitHub Actions or GitLab CI based on the platform parameter:

Webhook → Route by Platform → GitHub Actions API
                            → GitLab CI API
  1. Add a Webhook node to your canvas
  2. Set HTTP Method to POST
  3. Set the path to trigger-pipeline
  4. Set Response Mode to Respond to Webhook

The webhook will accept JSON payloads like:

{
  "platform": "github",
  "owner": "your-username",
  "repo": "your-repo",
  "workflow": "deploy.yml"
}
  1. Add a Switch node after the webhook
  2. Create conditions based on {{ $json.platform }}:
    • Route 1: github → GitHub Actions node
    • Route 2: gitlab → GitLab CI node

For GitHub, use an HTTP Request node:

URL:

https://api.github.com/repos/{{ $json.owner }}/{{ $json.repo }}/actions/workflows/{{ $json.workflow }}/dispatches

Method: POST

Headers:

Authorization: Bearer YOUR_GITHUB_TOKEN
Accept: application/vnd.github.v3+json

Body:

{
  "ref": "main"
}

For GitLab, use an HTTP Request node:

URL:

https://gitlab.com/api/v4/projects/{{ $json.project_id }}/trigger/pipeline

Method: POST

Body (form-data):

ref: main
token: YOUR_TRIGGER_TOKEN

Add a Respond to Webhook node at the end:

{
  "status": "triggered",
  "platform": "{{ $json.platform }}",
  "timestamp": "{{ $now }}"
}
# Trigger GitHub Actions
curl -X POST https://your-n8n-instance/webhook/trigger-pipeline \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "github",
    "owner": "your-username",
    "repo": "your-repo",
    "workflow": "deploy.yml"
  }'

# Trigger GitLab CI
curl -X POST https://your-n8n-instance/webhook/trigger-pipeline \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "gitlab",
    "project_id": "12345678",
    "trigger_token": "your-trigger-token"
  }'

Check your GitHub Actions or GitLab CI dashboard to confirm the pipeline was triggered.

Secure your webhook with a secret token:

// In a Code node after the webhook
if ($json.headers['x-webhook-secret'] !== 'your-secret') {
  throw new Error('Unauthorized');
}

Modify the payload to accept a branch parameter:

{
  "platform": "github",
  "owner": "your-username",
  "repo": "your-repo",
  "workflow": "deploy.yml",
  "branch": "develop"
}

Chain a Slack node to notify your team when pipelines are triggered:

Webhook → Route → Trigger API → Slack Notification → Respond
  • Verify the workflow file exists in .github/workflows/
  • Ensure your token has repo and workflow permissions
  • Check that workflow_dispatch trigger is defined in the workflow
  • Verify your trigger token is valid
  • Check the project ID is correct
  • Ensure the token has pipeline trigger permissions
  • Increase n8n’s webhook timeout in settings
  • Use async execution for long-running triggers
  • Return immediately and process in background
  1. Use environment variables for tokens - never hardcode
  2. Validate webhook payloads before processing
  3. Implement rate limiting to prevent abuse
  4. Log all trigger events for audit trails
  5. Use HTTPS for all webhook endpoints

You now have a flexible CI/CD trigger that can be called from anywhere - Slack bots, custom dashboards, monitoring alerts, or other n8n workflows. This centralizes your deployment orchestration and makes it easy to add new triggers without modifying your CI/CD configurations.

Download the complete workflow from our n8n Workflow Gallery and customize it for your needs.