build triggers
Different Types of Build Triggers in Jenkins with Real-Time Examples
πΉ Poll SCM
Use Case: Automatically build when code changes are pushed to Git (without a webhook).
Scenario: You want Jenkins to check the Git repository every 5 minutes. If changes are detected, it should trigger a build.
In the Schedule box, enter:
H/5 * * * *(This means: check every 5 minutes)
Save the job. Make a commit in your Git repo β push to the remote. Jenkins will poll every 5 minutes and run a build if it detects changes.
πΉ Build Periodically
Use Case: Run builds at scheduled times (like cron jobs).
Scenario: You want to run a job every night at 1 AM to back up logs or run a report.
Jenkins job β Configure, under Build Triggers, check β Build periodically.
Add schedule:
CopyEdit0 1 * * *(This means: run at 1:00 AM every day)
Save β Wait for the scheduled time β Jenkins runs the job automatically.
πΉ GitHub hook trigger for GITScm polling
Use Case: Trigger builds instantly when changes are pushed to GitHub.
Scenario: As soon as a developer pushes code to GitHub, Jenkins should run the job (faster than polling).
Jenkins job β Configure, under Build Triggers, check β GitHub hook trigger for GITScm polling. Save the job.
Go to GitHub repo β Settings β Webhooks. Add a new webhook:
Payload URL:
http://<your-jenkins-url>/github-webhook/Content type:
application/jsonChoose: Just the push event
Push a commit to GitHub β Jenkins job triggers instantly.
πΉ Trigger builds remotely (with authentication token)
Use Case: Trigger Jenkins jobs from external systems (like scripts, other tools, or pipeline integrations).
Scenario: You want to run a job from a custom Python script using a Jenkins API call.
Jenkins job β Configure, check β
Trigger builds remotely, enter a token (e.g., mytoken123). Save.
URL format:
Run from browser or CURL:
Add a Token to a Jenkins Job
Login to Jenkins β Go to your Freestyle job or create a new one. Click Configure for that job.
Scroll down to Build Triggers section. Check β Trigger builds remotely (e.g., from scripts).
In the Authentication Token field, enter a token like:
Click Save.
Trigger the Build Using the Token
Now you can trigger this job remotely using a browser or script.
URL Format:
Example: If your Jenkins is running on http://localhost:8080, job name is my-job, and token is mysecrettoken123, then:
Example CURL command from the original content:
πΉ Build after other projects are built
Use Case: Chain jobs (Job A triggers Job B after success).
Scenario: You want to run a testing job only after the deployment job finishes.
Create two jobs: Job-A and Job-B.
Go to Job-B β Configure, under Build Triggers, check β
Build after other projects are built, enter: Job-A. Save.
Run Job-A β After completion, Job-B starts automatically.
πΉ Parameterized Trigger (Advanced using plugins)
Use Case: Trigger another job and pass parameters.
Scenario: Job A deploys an app, and then Job B runs a test suite with environment as a parameter.
Install Parameterized Trigger Plugin.
Go to Job-A β Configure. Under Post-build Actions, choose Trigger parameterized build on other projects.
Enter job name: Job-B. Pass parameter: ENV=dev. Save and run β Job-B is triggered with ENV=dev.
πΉ Scripted Trigger via Pipeline (Using triggers {} block in Jenkinsfile)
triggers {} block in Jenkinsfile)Scenario: You want to define triggers as code inside the Jenkinsfile.
Sample Jenkinsfile (from original content):
Teaching Tip
Start with a Freestyle project.
Show a simple job first (like printing date or echo "Build triggered").
Gradually show one trigger at a time.
Use GitHub + webhook + Poll SCM for real-world impact.
Allow students to test triggering via CURL or Git push.
Do you want a combined Jenkins demo job with all trigger types? I can generate it for you as a ready-made teaching package β say "Yes" and tell me whether you prefer a Freestyle job, a Pipeline (Jenkinsfile), or both.
