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:
| |
Step-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:
| |
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:
| |
Method: POST
Headers:
| |
Body:
| |
Step 4: Configure GitLab CI Trigger#
For GitLab, use an HTTP Request node:
URL:
| |
Method: POST
Body (form-data):
| |
Step 5: Add Response Handler#
Add a Respond to Webhook node at the end:
| |
Testing the Workflow#
Test with cURL#
| |
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:
| |
Support Multiple Branches#
Modify the payload to accept a branch parameter:
| |
Add Slack Notifications#
Chain a Slack node to notify your team when pipelines are triggered:
| |
Troubleshooting#
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.
