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.

1

Steps to demo

Go to your Jenkins job β†’ Configure, scroll to Build Triggers, check βœ… Poll SCM.

2

In the Schedule box, enter:

H/5 * * * *

(This means: check every 5 minutes)

3

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.

1

Jenkins job β†’ Configure, under Build Triggers, check βœ… Build periodically.

2

Add schedule:

CopyEdit0 1 * * *

(This means: run at 1:00 AM every day)

3

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).

1

Jenkins job β†’ Configure, under Build Triggers, check βœ… GitHub hook trigger for GITScm polling. Save the job.

2

Go to GitHub repo β†’ Settings β†’ Webhooks. Add a new webhook:

  • Payload URL: http://<your-jenkins-url>/github-webhook/

  • Content type: application/json

  • Choose: Just the push event

3

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.

1

Jenkins job β†’ Configure, check βœ… Trigger builds remotely, enter a token (e.g., mytoken123). Save.

2

URL format:

3

Run from browser or CURL:

Add a Token to a Jenkins Job

1

Login to Jenkins β†’ Go to your Freestyle job or create a new one. Click Configure for that job.

2

Scroll down to Build Triggers section. Check βœ… Trigger builds remotely (e.g., from scripts).

3

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.

1

Create two jobs: Job-A and Job-B.

2

Go to Job-B β†’ Configure, under Build Triggers, check βœ… Build after other projects are built, enter: Job-A. Save.

3

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.

1

Install Parameterized Trigger Plugin.

2

Go to Job-A β†’ Configure. Under Post-build Actions, choose Trigger parameterized build on other projects.

3

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)

Scenario: You want to define triggers as code inside the Jenkinsfile.

Sample Jenkinsfile (from original content):


circle-info

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.