Jenkins CI-CD-7AM-MDP-1… 1st May 2023 Jenkins CI - CD ● CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. JENKINS ● Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. ● DevOps is a set of practices that works to automate and integrate the processes between software development and IT teams, so they can build, test, and release software faster and more reliably. ● CI/CD bridges the gaps between development and operation activities and teams by enforcing automation in building, testing and deployment of applications. ● The CI/CD practice, or CI/CD pipeline, forms the backbone of modern day DevOps operations. ● If your tasks are repeatable i.e done in the same way over a time period, then JENKINS can simply automate the repeatable process. Traditional Way ● Traditionally, the development team makes software available in a source code repository, then they give a call to operations and then operations starts building and deploys that software to the dev environment. Once this is done, there is usually a QA team which loads and executes tests on that build and makes it ready for production. Continuous Integration - CI ● Continuous Integration is a DevOps practice where developers regularly merge their code changes into a central repository(GitHub), after which automated builds and tests are run. ● In Continuous Integration each check-in is then verified by an automated build, ● In Continuous Integration each check-in is then verified by an automated build, allowing everyone to detect and be notified of problems with the build immediately Continuous Deployment - CD ● Continuous Deployment is an extension to Continuous Integration ● Continuous Deployment is a DevOps practice where code changes are automatically prepared for a release to Production. 3rd May 2023 Jenkins Setup Jenkins Setup ● Follow the below link to setup Jenkins https://www.jenkins.io/doc/book/installing/linux/#long-term-support-release-3 ● Jenkins runs on port 8080 ■ Add Security Group with port 8080 Jobs ● Simply put, you can think of Jenkins Jobs as a particular task or step in your project. ● A Job can be as simple as ○ compiling your source code or ○ performing a unit test or ○ performing a unit test or ○ package an application or ○ deploy an application etc ● Jobs are heart of jenkins DISK-USAGE - JOB > df -h OS - JOB ● Using Jenkins Display the OS Info ● Let say we need to modify the job behavior, we can configure the job at any given point of time ● When the job configuration is not updated properly, the jobs will fail. Build Triggers Build triggers are used for telling jenkins when to run the job. Build Periodically Provides a cron-like feature to periodically execute this project. It might be tests that should be run periodically (every morning for example) or a DB clean up Jenkins job or any other Jenkins job. Build Every Saturday Midnight 0 0 * * 6 5th May 2023 Plugins ● Plugins are the primary means of enhancing the functionality of a Jenkins environment to suit organization or user-specific needs. ● Like Google Chrome Browser has addons to extend chrome functionality, we have jenkins plugins ● There are over a thousand different plugins which can be installed on Jenkins and to integrate various build tools, cloud providers, analysis tools, report generations and much more. ● Plugins can be automatically downloaded, with their dependencies, from the Update Center. ● Installing GitHub Plugin, will give access to Source Code Management, where we can add repositories along with credentials, as credentials plugin will be installed ● In Build Triggers, we can get new trigger option called GitHub Trigger, which will automatically pull the changes into jenkins, when developers update new changes ● Installing Junit Plugin will give the ability to publish junit test reports from Postbuild Actions Installing Plugin The simplest and most common way of installing plugins is through the Manage Jenkins > Manage Plugins Check Plugins first, Available ● Folders - plugin allows users to create "folders" to organize jobs. Github Plugin ● Let’s say we have a private repository and we need credentials to work with private repository ● Now if we use open credentials, it’s insecure and can be easily prone to misuse the credetains or easily prone to malicious attacks ● So to resolve this we can GitHub Plugin ● After installing plugins, we got new options Private Repo - Job WebHooks ● Webhooks in GitHub allow external services to be notified when certain events happen ○ { external service - jenkins } ● One of the main steps of implementing CI/CD is integrating your Source Code ● One of the main steps of implementing CI/CD is integrating your Source Code Repository tools with your CI Tools. ● This saves you time and keeps your project updated all the time. One of the most popular and valuable SCM tools is GitHub. Will see how to integrate Jenkins with GitHub projects. ● The integration will help you to: ● Schedule your build ● Pull your code and data files from your GitHub repository to your Jenkins machine ● Automatically trigger each build on the Jenkins server, after each Commit on your Git repository 8th May 2023 Notifications Email - Notify Build ● Jenkins provides you with an email notification service through which you can report the build status and testing results to the team. ● If the build is not successful then the team of developers are notified about the status of the build. This can be done with the help of an Mailer plugin in Jenkins ● Using the email plugin, you configure the email details of the concerned person who should be notified in case of build failure. ● Once the developer is notified about the error, he then fixes it and again pushes the code to GitHub. After this Jenkins again pulls the code from GitHub and prepares a fresh build. ● Use the following steps to setup the notifications in Jenkins ● Go to the Jenkins home page and click the ‘Manage Jenkins’ menu option. Then, select the ‘Configure System’ option > You don't see any Email Notification option in there ● Jenkins home page > Manage Jenkins > Manage Plugins > Search : email > Select : Mailer plugin > Install GMAIL Setup ● Jenkins home page > Manage Jenkins > Configure System > Email Notification > ● Enter the SMTP server name under ‘Email Notification’. Click the ‘Advanced’ button and then click the checkbox next to the ‘Use SMTP Authentication’ option. Now, set the following fields. ● SMTP server name : smtp.gmail.com ● User name: user_email_id@gmail.com ● Password: 123456 ● Use SSL : Checked ● SMTP Port: 465 ● For the above configuration to work, you need to add security measures given by google. An additional configuration is required in the Gmail account from which the mail is being triggered. This step authorizes apps like Jenkins to use the Gmail account. ● https://support.google.com/accounts/answer/6010255 ● Go to the "Less secure apps" section in My Account. Next to "Access for less secure apps," select Turn on. (Note to G Suite users: This setting is hidden if your administrator has locked less secure app account access.) ● Allow new devices using the link: https://g.co/allowaccess ● After this emails will be triggered successfully. Implement Three things with given SMTP settings 1. Disable two factor authentication: https://myaccount.google.com/security 2. Allow less secure apps : https://www.google.com/settings/security/lesssecureapps 3. Allow new devices using the link: https://g.co/allowaccess SMTP Settings: ● smtp.gmail.com ● Port: 465 ● Use SSL ● From Email Address ● Gmail Username ● Gmail Username ● Gmail Password SonarQube ● SonarQube is an open source platform developed by SonarSource for continuous inspection of Code Quality ● SonarQube offers reports on duplicated code, coding standards, unit tests, bugs and security vulnerabilities ● SonarQube provides fully automated analysis and integration with Continuous Integration tools like Jenkins ● SonarQube is a Java application that requires a Java Runtime Environment. Quality Model ● Bugs track code that is demonstrably wrong or highly likely to yield unexpected behavior. ● Vulnerabilities are raised on code that is potentially vulnerable to exploitation by hackers. ● Code Smells will confuse maintainers or give them pause. They are measured primarily in terms of the time they will take to fix. Setting Up SonarQube ● SonarQube Requires “Standard_D2s_v3 size to work ● SonarQube works on “port 9000”, make sure to add port 9000 as part of your Security Group ● Install Docker ○ > curl -fsSL https://get.docker.com -o get-docker.sh ○ > sh get-docker.sh ● Setup SonarQube Container ○ sudo docker container run -dt --name sonarqube -p 9000:9000 sonarqube > git clone -b vm-docker-cicd https://github.com/KonaMarsTech/lms-public.git > cd lms-public/webapp > sudo docker run --rm -e SONAR_HOST_URL="http://104.45.149.182:9000" -e SONAR_LOGIN="sqp_a84326d3a30822428c5882fdf109b13a8a2714d0" -v ".:/usr/src" sonarsource/sonar-scanner-cli -Dsonar.projectKey=lms 10th May 2023 10th May 2023 Nexus Binary Repository Manager ● A Binary repository manager/Artifactory is a software tool designed to optimise the download and storage of binary files used and produced in software development. development. ● It centralises the management of all the binary artifacts generated and used by the organization. ● A binary repository is a software repository for packages, artifacts and their corresponding metadata. ● The Binary repository manager we are using is Nexus Setting Up Nexus ● Nexus Requires “Standard_D2s_v3 size to work ● Nexus works on “port 8081”, make sure to add port 8081 as part of your Security Group ● Install Docker ○ > curl -fsSL https://get.docker.com -o get-docker.sh ○ > sh get-docker.sh ● Setup Nexus Container ○ sudo docker run -d -p 8081:8081 --name nexus sonatype/nexus3 ○ curl -v -u username:password --upload-file <file> <nexus-repo-link> ○ curl -u admin:Admin123* -X GET 'http://20.172.187.108:8081/repository/lms/dist-1.1.zip' --output dist1.1.zip ○