Building a CI/CD Pipeline Trigger with n8n
Introduction
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.
Prerequisites
Before starting, ensure you have:
- An n8n instance (self-hosted or n8n Cloud)
- GitHub Personal Access Token with
repoandworkflowpermissions - Or GitLab API token with
apiscope - A repository with existing CI/CD workflows
Workflow Overview
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 APIStep-by-Step Setup
Step 1: Create the Webhook Trigger
- Add a Webhook node to your canvas
- Set HTTP Method to
POST - Set the path to
trigger-pipeline - 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"
}Step 2: Add Platform Routing
- Add a Switch node after the webhook
- Create conditions based on
{{ $json.platform }}:- Route 1:
github→ GitHub Actions node - Route 2:
gitlab→ GitLab CI node
- Route 1:
Step 3: Configure GitHub Actions Trigger
For GitHub, use an HTTP Request node:
URL:
https://api.github.com/repos/{{ $json.owner }}/{{ $json.repo }}/actions/workflows/{{ $json.workflow }}/dispatchesMethod: POST
Headers:
Authorization: Bearer YOUR_GITHUB_TOKEN
Accept: application/vnd.github.v3+jsonBody:
{
"ref": "main"
}Step 4: Configure GitLab CI Trigger
For GitLab, use an HTTP Request node:
URL:
https://gitlab.com/api/v4/projects/{{ $json.project_id }}/trigger/pipelineMethod: POST
Body (form-data):
ref: main
token: YOUR_TRIGGER_TOKENStep 5: Add Response Handler
Add a Respond to Webhook node at the end:
{
"status": "triggered",
"platform": "{{ $json.platform }}",
"timestamp": "{{ $now }}"
}Testing the Workflow
Test with cURL
# 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"
}'Verify in CI/CD Platform
Check your GitHub Actions or GitLab CI dashboard to confirm the pipeline was triggered.
Customization Options
Add Authentication
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');
}Support Multiple Branches
Modify the payload to accept a branch parameter:
{
"platform": "github",
"owner": "your-username",
"repo": "your-repo",
"workflow": "deploy.yml",
"branch": "develop"
}Add Slack Notifications
Chain a Slack node to notify your team when pipelines are triggered:
Webhook → Route → Trigger API → Slack Notification → RespondTroubleshooting
GitHub Returns 404
- Verify the workflow file exists in
.github/workflows/ - Ensure your token has
repoandworkflowpermissions - Check that
workflow_dispatchtrigger is defined in the workflow
GitLab Returns 401
- Verify your trigger token is valid
- Check the project ID is correct
- Ensure the token has pipeline trigger permissions
Webhook Timeout
- Increase n8n’s webhook timeout in settings
- Use async execution for long-running triggers
- Return immediately and process in background
Security Best Practices
- Use environment variables for tokens - never hardcode
- Validate webhook payloads before processing
- Implement rate limiting to prevent abuse
- Log all trigger events for audit trails
- Use HTTPS for all webhook endpoints
Conclusion
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.