Triggering Jobs with Jenkins
- Jenkins supports triggering the builds based on
- Schedule
- changes in branch
- poll scm
- GitHub WebHook
- Script Execution
- Build after some other job

- To work with scheduling we need to understand cron syntax
MINUTE HOUR DOM MONTH DOW
MINUTE Minutes within the hour (0–59)
HOUR The hour of the day (0–23)
DOM The day of the month (1–31)
MONTH The month (1–12)
DOW The day of the week (0–7) where 0 and 7 are Sunday.
- To create cron expression use Refer Here
- Lets trigger the game of life every 15 minutes through out the day
- Free Style Job

- Declarative. Refer Here for changes

- Exercise: Try to do the same to build the job for every 15 minutes on weekdays between 10 to 19 IST
- Lets trigger the build only when there are changes
- poll scm: Jenkins will look into remote git repository for changes, we need to configure how frequently jenkins will poll git/scm
- Poll SCM will initiate build only when there are changes. In the below configuration we have asked to check/poll git every minute and build whenever there is a change.


- Lets write a declarative pipeline to build code every 30 minutes only when git has new changes Refer Here for changes

Day Builds and Night Builds
- Day Builds represent builds during active development time. During this we will have pipelines which will give feedback to developers on their commited code quality.This build will have
- build
- package
- unit test
- Static Code Analysis
- Night Build represents the work of the team for the entire day. This build will have
- build
- package
- unit test
- Static Code Analysis
- store the package into binary repository
- creating/update test environments with latest packages and executing automated tests
- Generate the reports which QA and management team will be interested.
- Day Builds are configured to run
- on every change done by dev team if the time taken to perform this is less (
< 20 mins) - on schedule (for every hour or 2 hours)
- on every change done by dev team if the time taken to perform this is less (
Handling User Inputs
- User Inputs are provided as parameters
- Lets give a string parameter for maven goal


- Now lets using parameter in maven build steps

- Now lets build the job



- Try giving Branch name
- Now lets try the same thing with choice parameter




- Lets try to add the same to declarative pipelines
- Refer Here for string parameter

- Refer Here for the choice parameter
- Refer Here for string parameter
- In Declarative pipelines we can also take additional inputs Refer Here
Notifications
- For testing, lets setup fake smtp server and inbox in mailtrap.io
- Lets configure credentials for notifications into jenkins. Navigate to Manage Jenkins => Configure System => E-mail Notification


- Now lets configure jenkins to send emails on job status




- Try to do the same in declarative pipeline.
- Slack Notification configuration: Refer Here
- Microsoft Teams Notification Refer Here
Exercise
- Build spring petclinic project using gradle Refer Here
