Jenkins Job Triggers
1. Poll SCM
Overview
Poll SCM periodically scans the repository for changes and triggers a build when updates are detected.
Enable Poll SCM
- Open the Jenkins job.
- Go to Configure.
- Scroll to Build Triggers.
- Enable Poll SCM.
- Add a cron expression.
Example:
This checks the repository every 5 minutes.
2. Build after other projects are built
Overview
This trigger allows a Jenkins job to start automatically after another specified job finishes successfully.
Enable the Trigger
- Open your Jenkins job.
- Click Configure.
- Scroll to Build Triggers.
- Enable Build after other projects are built.
- In Projects to watch, enter the name of the upstream job.
Example: UpstreamJobName
Test the Trigger
- Start the upstream job manually.
- Wait for it to finish.
- Verify that the downstream job starts automatically.
Workflow
3. Remote Trigger
Overview
Remote triggering allows you to start a Jenkins job from an external script or system using an HTTP request.
Enable the Remote Trigger
Requirements
curlwget
Step 1 — Enable Remote Trigger in Jenkins
- Open your Jenkins job.
- Click Configure.
- Go to Build Triggers.
- Enable:
- Create a token in Authentication Token.
Example:
Your trigger URL format will be:
Example:
Step 2 — Generate Jenkins API Token
- Click your username (top-right corner).
- Go to Security.
- Click Add new Token.
- Copy the token.
Example credentials format:
Example:
Step 3 — Generate Jenkins Crumb (CSRF Protection)
Run the following command to retrieve the Jenkins crumb:
wget -q \
--auth-no-challenge \
--user USERNAME \
--password API_TOKEN \
--output-document - \
"http://JENKINS_IP:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)"
Example output:
Step 4 — Trigger the Jenkins Job
Use curl to trigger the job:
curl -X POST \
http://USERNAME:API_TOKEN@JENKINS_IP:8080/job/JOB_NAME/build?token=TOKEN_NAME \
-H "Jenkins-Crumb:CRUMB"
Example
curl -X POST \
http://admin:1188c983482ac7f4a125a83c1316f43b30@localhost:8080/job/BuildTriggerTest/build?token=mybuildtoken \
-H "Jenkins-Crumb:eb5d4ffd2ee8cabb4d15ee6d515bba5a6cc7f2045b4eb640e43914342d851ca8"
This will remotely trigger the Jenkins job BuildTriggerTest.