A TypeScript Express server that relays GitHub webhooks to Jenkins servers. This server acts as a secure intermediary that validates incoming GitHub webhooks and forwards them to your internal Jenkins instance for triggering builds.
- 🔐 Secure webhook validation using GitHub webhook secrets
- 🚀 High-performance relay to Jenkins servers
- 📊 Health monitoring with status endpoints
- 🧹 Input validation using cleaners for network and file traffic
- 🔧 Configurable ports and target servers
- 📝 Comprehensive logging for debugging and monitoring
npm installUpdate serverConfig.json with your settings:
{
"couchDbFullpath": "http://admin:admin@127.0.0.1:5984",
"incomingPort": 8008,
"targetJenkinsUrl": "http://your-jenkins-server:8080/github-webhook/",
"webhookPath": "/webhook",
"githubWebhookSecret": "your-github-webhook-secret-here"
}incomingPort: Port for the relay server to listen ontargetJenkinsUrl: Full URL to your Jenkins GitHub webhook endpointwebhookPath: Path where GitHub will send webhooks (default:/webhook)githubWebhookSecret: (Optional) Secret for validating GitHub webhook signaturescouchDbFullpath: Legacy configuration (can be ignored for webhook relay)
# Build the TypeScript code
npm run build.server
# Start the server
npm start
# Or for development with auto-reload
npm run start.dev- Go to your GitHub repository settings
- Navigate to "Webhooks"
- Click "Add webhook"
- Set the payload URL to:
http://your-relay-server:8008/webhook - Set content type to
application/json - Add your webhook secret (if configured)
- Select the events you want to trigger builds (typically "Push" and "Pull requests")
Make sure your Jenkins server is configured to accept GitHub webhooks:
- Install the "GitHub Plugin" in Jenkins
- Configure your Jenkins job to trigger on GitHub webhook
- Set the webhook URL in your job configuration
The server provides several endpoints for monitoring:
GET /health- Overall health status including Jenkins connectivityGET /api/config- Current configuration (sensitive data hidden)GET /api/template- Legacy endpoint for compatibility
Example health check response:
{
"status": "healthy",
"relay": {
"targetUrl": "http://your-jenkins-server:8080/github-webhook/",
"webhookPath": "/webhook",
"jenkins": "reachable"
},
"timestamp": "2024-01-15T10:30:00.000Z"
}When a githubWebhookSecret is configured, the server validates incoming webhooks using HMAC-SHA256 signatures to ensure they're from GitHub.
All incoming data is validated using the cleaners library:
- Webhook headers are validated for required GitHub fields
- Payload structure is verified
- Outgoing requests to Jenkins are validated
- Network traffic is sanitized
- Invalid payloads are rejected with appropriate HTTP status codes
- Network errors are caught and logged
- Timeouts prevent hanging requests
- Sensitive information is masked in logs
npm run build.server- Build server TypeScript codenpm run start- Start production servernpm run start.dev- Start development server with auto-reloadnpm run lint- Run ESLintnpm run fix- Auto-fix ESLint issuesnpm run clean- Clean build artifacts
src/
├── server/
│ ├── index.ts # Main server application
│ ├── webhook-relay.ts # Webhook relay service
│ └── webhook-cleaners.ts # Input validation cleaners
├── config.ts # Configuration schema and loading
├── common/ # Shared utilities
└── client/ # React client (untouched)
This project uses eslint-config-standard-kit for consistent code style:
npm run lint # Check for issues
npm run fix # Auto-fix issues-
"Invalid GitHub webhook signature"
- Check that your
githubWebhookSecretmatches the secret configured in GitHub - Ensure the webhook is sending the
X-Hub-Signature-256header
- Check that your
-
"Failed to relay webhook to Jenkins"
- Verify your
targetJenkinsUrlis correct and accessible - Check Jenkins logs for any errors processing the webhook
- Use the
/healthendpoint to test connectivity
- Verify your
-
"Request timeout"
- Check network connectivity to Jenkins
- Verify Jenkins is responding to requests
- Consider increasing timeout in the webhook relay service
Enable verbose logging by checking the console output when running with npm run start.dev. The server logs:
- Incoming webhook events
- Relay attempts and responses
- Errors and warnings
MIT License