Jenkins Jenkins Build Triggers and Scheduling 2 — Questions and Answers
Question 1: In Jenkins Pipeline, which directive is used to define build triggers in a Declarative Pipeline?
- triggers {} (Correct answer)
- schedule {}
- when {}
- cron {}
Correct answer: triggers {}
The 'triggers {}' directive inside a Declarative Pipeline's pipeline block is used to define automated triggers like cron, pollSCM, or upstream.
Question 2: What Jenkins Pipeline trigger syntax polls the SCM every 10 minutes?
- pollSCM('H/10 * * * *') (Correct answer)
- cron('*/10 * * * *')
- scm('H/10 * * * *')
- poll('H/10 * * * *')
Correct answer: pollSCM('H/10 * * * *')
The pollSCM trigger in a Declarative Pipeline accepts a cron string that defines how often Jenkins checks the repository for changes.
Question 3: Which Jenkins feature allows a build to be triggered automatically when a pull request is opened in GitHub?
- GitHub Pull Request Builder plugin (Correct answer)
- Poll SCM trigger
- Trigger builds remotely
- Build periodically trigger
Correct answer: GitHub Pull Request Builder plugin
The GitHub Pull Request Builder plugin listens for GitHub webhook events for PR creation and triggers Jenkins builds for validation.
Question 4: If you want a Jenkins job to run only on weekdays (Monday through Friday) at 6 AM, what cron expression would you use?
- 0 6 * * 1-5 (Correct answer)
- 6 0 * * 1-5
- 0 6 * * MON-FRI
- 6 * * * 1-5
Correct answer: 0 6 * * 1-5
In cron format, '0 6 * * 1-5' means minute 0, hour 6, any day/month, and weekdays 1-5 (Monday through Friday).
Question 5: What happens in Jenkins when both 'Poll SCM' and a webhook are configured for the same job?
- Both can trigger builds; the webhook triggers immediately while Poll SCM serves as a fallback (Correct answer)
- Poll SCM overrides the webhook
- The webhook overrides Poll SCM
- Jenkins throws a configuration error
Correct answer: Both can trigger builds; the webhook triggers immediately while Poll SCM serves as a fallback
Having both configured is a valid setup; webhooks provide immediate triggers while Poll SCM can catch cases where webhooks fail to deliver.
Question 6: Which Jenkins plugin provides the ability to trigger builds based on a Bitbucket webhook?
- Bitbucket Plugin (Correct answer)
- Generic Webhook Trigger Plugin
- SCM Sync Plugin
- Multi-Branch Pipeline Plugin
Correct answer: Bitbucket Plugin
The Bitbucket Plugin integrates with Bitbucket's webhook system to trigger Jenkins builds when code is pushed or pull requests are created.
Question 7: In Jenkins Declarative Pipeline, how do you configure a build to trigger via a cron schedule every hour?
- triggers { cron('H * * * *') } (Correct answer)
- schedule { hourly() }
- triggers { pollSCM('H * * * *') }
- when { cron('H * * * *') }
Correct answer: triggers { cron('H * * * *') }
The cron() trigger inside the triggers {} block uses a cron expression to run the pipeline at scheduled times regardless of SCM changes.
In Jenkins Pipeline, which directive is used to define build triggers in a Declarative Pipeline?