DevOps Classroomnotes 24/Sep/2022

Jenkins Contd

Triggering Jenkins Job on every new commit

  • In Build Triggers, we have an option to poll scm where jenkins watches your source code repository (git) for the new changes i.e. commit in git.
  • While using poll scm we use CRON Syntax to configure how frequently jenkins will poll SCM for changes
  • Scenario 1: Build time is less
    • Trigger build ASAP when developer pushes the commit
      Preview
      Preview
    • Now push a change & you will observe an build executor getting assigned and executed.
      Preview
    • This is quite a common configuration for day build in projects where we have build times less than 10-15 minutes.
  • Scenario 2: Build time is more (50 minutes)
    • In this case we will configure Day build to run every n minutes or hours, in the above case every hour.
    • Lets configure Poll SCM to poll git for changes every hour
      Preview
  • Scenario 3: Build for the release to testing team next day
    • Here we need to build the code, deploy the package created on some servers.
    • Probably run some automated tests.
    • This is reffered as nightly build
    • This is generally configured to run at a particular time on every working day.
    • Lets configure to build at 11:30 PM IST on every weekday
      Preview

Upstream and Downstream Jobs

  • We can link/chain multiple jobs by using
    • PostBuild Actions => Build other Project
    • Build Triggers => Build after Job
      Preview
      Preview

Scripted Pipeline With Free Style References

  • I Want to build a spring petclinic project
    Preview
  • In scripted pipeline, we need to select node and then stage and then step
    Preview
    Preview
  • Then lets use Scripted Pipeline Sytnax Generator to generate pipeline
    Preview
    Preview
  • Ideally the Generated script should be part of the source code and every change can be tracked as it is part of version control system.
  • When you define your steps in pipeline in any file which is part of version control we refer it as pipeline as Code.
  • The Scripted Pipeline which we generated in the class
node('OPENJDK-11-MAVEN') {
    stage('vcs') {
        git branch: 'REL_INT_1.0', url: 'https://github.com/GitPracticeRepo/spring-petclinic.git'
    }
    stage("build") {
        sh '/opt/apache-maven-3.8.6/bin/mvn package'
    }
    stage("archive results") {
        junit '**/surefire-reports/*.xml'

    }
}

Exercise:

  • Find out the different environment variables
    Preview

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner