What is the difference between a webhook trigger and a scheduled trigger in CI/CD?
Understand the difference between webhook and scheduled triggers in CI/CD — event-driven versus time-driven pipelines, with use cases and examples.
Expected Interview Answer
A webhook trigger starts a pipeline in response to an event, such as a push or pull request, delivered by an HTTP callback the moment it happens. A scheduled trigger starts a pipeline at fixed times using a cron-style schedule, regardless of whether anything changed.
Webhook triggers are event-driven: the source system (like GitHub) sends an HTTP POST to the CI server when something occurs, so builds run immediately and reflect the latest change. Scheduled triggers are time-driven: the CI system fires the pipeline on a recurring clock, ideal for work that should happen periodically rather than per change. Most real pipelines use both — webhooks for fast feedback on commits, and schedules for nightly builds, dependency scans, or cache warming.
- Webhooks give immediate feedback on every change
- Schedules run routine jobs without manual effort
- Webhooks avoid wasted runs when nothing changed
- Schedules are ideal for nightly builds and periodic scans
- Combining both covers reactive and proactive needs
AI Mentor Explanation
A webhook trigger is like the third umpire reacting the instant a review is requested — it responds to a specific event as it happens. A scheduled trigger is like the fixed drinks break that comes every set number of overs whether or not anything dramatic occurred. One fires on the event; the other fires by the clock, and a well-run match uses both.
Step-by-Step Explanation
Step 1
Identify the trigger source
Decide whether the pipeline should react to an external event or run on a recurring clock.
Step 2
Configure a webhook
Register a webhook so the source system POSTs to the CI server on events like push or pull_request.
Step 3
Configure a schedule
Define a cron expression for time-driven runs such as a nightly build or weekly dependency scan.
Step 4
Handle the payload or context
Webhook runs use the event payload for the exact commit; scheduled runs typically build the latest default-branch state.
Step 5
Combine as needed
Use webhooks for fast per-change feedback and schedules for routine maintenance jobs in the same pipeline.
What Interviewer Expects
- Clear event-driven versus time-driven distinction
- Knowledge that webhooks are HTTP callbacks from the source system
- Understanding of cron-style scheduling
- Realistic use cases for each trigger type
- Awareness that pipelines commonly use both together
Common Mistakes
- Saying a webhook trigger runs on a timer
- Thinking scheduled triggers react to code changes
- Assuming you must choose only one trigger type
- Confusing a webhook with a poll-based check
- Forgetting that scheduled runs build the latest branch state, not a specific commit
Best Answer (HR Friendly)
“A webhook trigger runs the pipeline the moment something happens, like someone pushing new code. A scheduled trigger runs the pipeline at set times, like every night, no matter what. Teams usually use both — instant feedback for changes and regular runs for routine checks.”
Code Example
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '0 2 * * *' # nightly build at 02:00 UTC
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm testFollow-up Questions
- How does a webhook differ from polling the repository for changes?
- What is a cron expression and how do you read one?
- When would you prefer a scheduled build over an event-driven one?
- How do you secure an incoming webhook?
- Can a scheduled trigger run on a specific commit rather than the latest branch?
MCQ Practice
1. A webhook trigger fires when?
Webhook triggers are event-driven — the source system sends an HTTP callback the moment an event like a push occurs.
2. Which is the best use case for a scheduled trigger?
Scheduled triggers run on a recurring clock, making them ideal for periodic jobs like nightly scans that need not react to a change.
3. What syntax typically defines a scheduled trigger?
Scheduled triggers are usually defined with a cron expression specifying the minute, hour, day, and month of each run.
Flash Cards
What triggers a webhook build? — An event, delivered as an HTTP callback from the source system the moment it happens.
What triggers a scheduled build? — A recurring time defined by a cron schedule, independent of any code change.
Best use for a schedule? — Routine periodic jobs like nightly builds, dependency scans, or cache warming.
Why use both? — Webhooks give fast per-change feedback while schedules cover proactive, recurring maintenance.