0
0
Jenkinsdevops~10 mins

Triggers directive in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Triggers directive
Start Jenkins Job Configuration
Add triggers directive
Define trigger type
Jenkins monitors trigger
Trigger fires job
Job runs automatically
End
The triggers directive is added in Jenkins job config to tell Jenkins when to start the job automatically.
Execution Sample
Jenkins
pipeline {
  triggers {
    cron('H/15 * * * *')
  }
  stages {
    stage('Build') { steps { echo 'Building...' } }
  }
}
This Jenkins pipeline runs the build stage automatically every 15 minutes using the cron trigger.
Process Table
StepActionTrigger EvaluatedResultJob Status
1Start Jenkins job configurationNo trigger yetWaiting for triggerIdle
2Add triggers directive with cron('H/15 * * * *')Cron trigger setJenkins schedules job every 15 minutesIdle
3Time reaches scheduled cron timeCron trigger firesJob starts automaticallyRunning
4Job executes build stageN/ABuild stage runs and completesSuccess
5Wait for next cron timeWaitingJob idle until next triggerIdle
💡 Job waits idle until next scheduled cron trigger fires again
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Job StatusIdleIdleRunningSuccessIdle
Trigger StateNoneCron setFiredN/AWaiting
Key Moments - 2 Insights
Why doesn't the job run immediately after adding the triggers directive?
Because the trigger only schedules the job to run at specific times (e.g., every 15 minutes). See execution_table step 2 and 3 where the job waits idle until the cron time.
What happens if the trigger condition is never met?
The job stays idle and never runs automatically. This is shown in execution_table step 5 where the job waits for the next trigger.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the Job Status at Step 3 when the trigger fires?
ASuccess
BIdle
CRunning
DFailed
💡 Hint
Check the 'Job Status' column at Step 3 in the execution_table.
At which step does the Jenkins job complete successfully?
AStep 4
BStep 2
CStep 3
DStep 5
💡 Hint
Look for 'Build stage runs and completes' in the 'Result' column.
If the cron trigger was removed, what would be the Job Status after Step 2?
ARunning
BIdle
CSuccess
DFailed
💡 Hint
Without a trigger, the job waits idle. See 'Trigger State' in variable_tracker after Step 2.
Concept Snapshot
Triggers directive in Jenkins pipeline:
- Use triggers { cron('schedule') } to auto-start jobs
- Jenkins monitors triggers and runs jobs when conditions match
- Jobs stay idle until trigger fires
- Common triggers: cron, pollSCM, upstream
- Helps automate job runs without manual start
Full Transcript
The triggers directive in Jenkins pipeline is used to tell Jenkins when to start a job automatically. You add it inside the pipeline block under triggers. For example, cron('H/15 * * * *') schedules the job to run every 15 minutes. Jenkins watches the trigger and when the time matches, it fires the job. The job status changes from idle to running, then success after the build stage completes. If the trigger condition is not met, the job stays idle waiting. This automation helps run jobs on schedule without manual intervention.