DevOps Classroomnotes 04/Mar/2023

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
      Preview
  • 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
    Preview
  • Declarative. Refer Here for changes
    Preview
  • 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.
    Preview
    Preview
  • Lets write a declarative pipeline to build code every 30 minutes only when git has new changes Refer Here for changes
    Preview

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)

Handling User Inputs

  • User Inputs are provided as parameters
  • Lets give a string parameter for maven goal
    Preview
    Preview
  • Now lets using parameter in maven build steps
    Preview
  • Now lets build the job
    Preview
    Preview
    Preview
  • Try giving Branch name
  • Now lets try the same thing with choice parameter
    Preview
    Preview
    Preview
    Preview
  • Lets try to add the same to declarative pipelines
  • 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
    Preview
    Preview
  • Now lets configure jenkins to send emails on job status
    Preview
    Preview
    Preview
    Preview
  • 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

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube