Saturday, 8 February 2020

DevOps - Jenkins

Software Development evolution
  • Water fall
    • Requirements are clear and fixed
    • Product definition is stable
  • Agile
    • Requirements change frequently
    • Development needs to be fast
  • Devops
    • Requirements change frequently
    • Development needs to be fast 
    • Operations need to be agile/fast 

DevOps is a Software development Approach 

  • Continuous Development
    • Planning & Coding
  • Continuous Testing
    •  
  • Continuous Integration
    • Jenkins
    • Process of automated build & Tests

  • Continuous Deployment
    • Keeping application deployable at any point of time 
    • Configuration management(server configuration)
    • Containerazation
  • Continous Delivery
    • Practice of keeping code base deployable at any point of time. It is beyond making sure automated tests pass to have all configurations necessary to push to production.
  • Continuous Monitoring

Jenkins

  •  Continuous Integration
    • It is a development practice that requires developers to integrate code into a shared repository several times a day
    • Each checkin is verified by automated build which helps to detect problems early
  • Process
    • Developers checkout code in their workspace
    • Commit the new changes to repository
    • CI server monitors the repository and checks out changes when they occur
    • CI server builds the system and runs unit & integration tests
    • CI server releases deployable artifacts for testing
    • CI server assigns a build label to the version of code it just built
  • Jenkins
    • CI/CD tool written in java
    • Used to build & deliver 
    • Forked from another product HUDSON
    • It is server based application that requires server like tomcat
    • why it popular
      • Monitoring of repeated tasks which arise in development of a project

  • Installation 
    • docker run -p 7979:8080 -p 50000:50000 -v ~/jenkins_home:/var/jenkins_home jenkins/jenkins:lts
    • admin/wcalto  or vdesu/wcalto
    • Container
      • docker exec -it -u root jenkins /bin/bash
         
Jenkins terminoloty
  • Jenkins Job
    • Any runnable tasks that are controlled and monitored by Jenkins
  • Slave/Node
    • VMs that are setup to build projects for a master
  • Jenkins Slave
    • Jenkins run separate program called "Slave Agents" on Slaves
    • Slaves are connected to master 
  • Node
    • All machines that are part of Jenkins grid, slaves & master
  • Executor
    • Separate stream of builds to be run on a Node in parallel
  • Plugins
    • Piece of software that extends core functionality of the core Jenkins Server

Docker
    https://www.youtube.com/watch?v=7KCS70sCoK0&list=PLy7NrYWoggjw_LIiDK1LXdNN82uYuuuiC&index=6
  •  docker run -d -v jenkins_home:/var/jenkins_home -p 7575:8080 -p 50000:50000 jenkins/jenkins:lts
    • 7575 for external visibility
    • 50000 is master/slave communication
    • -d for detached mode
    • -v -> named volume
  • docker logs <container id>
  • copy pwd from logs to eda5e9224b9c451d8e1e6ee22fdc873f  localhost:7575
  • install standard plugins
Types of Projects
  • Freestyle
    • simple & single test
  • Pipeline
    • Whole delivery flow eg: test, build...
  • Multibranch Pipeline
    • For multiple branches
    •  
Maven Freestyle project: https://www.youtube.com/watch?v=kO7wrtY2b3E
Jenkins Pipeline- https://www.youtube.com/watch?v=pzbrVVy6ul4
  • Jenkins pipeline means Pipeline as a code
  • we have 2 types of jenkins pipeline
    • Scripted
      • needs groovy script knowledge
    • Declarative
      • simple way
 
Jenkinsfile-> Pipeline as a code ie scripted pipeline
https://www.youtube.com/watch?v=pzbrVVy6ul4&list=RDCMUC_evcfxhjjui5hChhLE08tQ&start_radio=1&t=0
  • scripted 
    • first syntax
    • groovy engine
    • adv scripting capabilities
    • difficult to start 
    • node{
          stage(‘sim checkout’){
              git ‘<url>’
          }
          stage(‘compile pkg’){
              def mvnHome = tool name: ‘maven-3’,type: ‘maven’
              sh “${mvnHome}/bin/mvn package”
      }
      }
  • declarative
    • recent edition
    • easy to start but not powerful
    •  predefined structure
    • pipeline {
        agent any
          stages {
            stage("build") {
              steps {
              }
            }
          }
        }
    • agent - where to execute 
    • stages - where the whole work happens
    • steps - build, test, deploy
  •