Mastering Jenkins: A Guide to Continuous Integration

Jenkins is a CI/CD (Continuous Integration & Continuous Deployment) tool which helps the developers to test, build and deploy their code.

Issues before Jenkins

Before the arrival of Jenkins, the below lifecycle was followed

  • Many developers from a project used to commit their code without testing individual modules

  • Integration process with the repository was very difficult

  • Project releases were infrequent

  • Without any feedback they didn't know if their code would introduce any bugs.

After Jenkins

  • Continuous Integration have made life easier for developers where they can test their code for each enhancement, check the build

  • Releases have become frequent and dev's were notified in case of any issues.

Prerequisites

If you are going to use Jenkins for a Java Spring boot project then install the below in your machine

  1. Java

  2. Maven

Installation Procedure

Refer the below procedure in case of a Windows OS https://www.jenkins.io/doc/book/installing/windows/

In case of a mac OS, jenkins (msi file) can be downloaded using the below link

https://www.jenkins.io/download/lts/macos/

  • Install the latest version

  •     brew install jenkins-lts
    
  • To start the Jenkins service

  •     brew services start jenkins-lts
    
  • After installing, unlike Windows, Mac OS will not show the admin password. I faced the same issue and followed the below procedure to get the password

    • Navigate to cd /Users/mac

    • Go to the secrets folder cd .jenkins/secrets

    • View the content inside the password file by using cat initialAdminPassword

After the above steps, go to localhost:8080 and enter the admin password. (8080 is the default port)

Select "Install suggested plugins" and wait for it to complete in the Customize Jenkins page and provide all the required details like user-id/email etc. in next page

Yah--ooo, now you can start using Jenkins.

Create a new job

  1. Create a new github repository

  2. Go to Jenkins homepage -> Click on New Item -> Enter name as "Spring Jenkins" (or any custom name)

  1. Select Github project in the options and provide the URL (repository that was created in step 1)

  2. Select Source Code Management as Git and provide the credentials of the jenkins in username and password.

  3. Select the branch (Main/feature branch)

  4. Build Triggers and Build Environment are respectively used to define schedules for the build and what is supposed to happen after the build.

  5. Under the Build Steps, select Maven/Gradle and then give the goal as install which will execute each time a build is triggered in Jenkins.

  6. In the post-build Actions, can define steps to send an email/publish tests accordingly.

To run a Jenkins Build

Go to Jenkins Dashboard -> navigate to the project -> click "Build Now"

If you run into any issues like "the then the below link would help

https://stackoverflow.com/questions/23906352/git-pullrequest-job-failed-couldnt-find-any-revision-to-build-verify-the-repo

Start and stop Jenkins

Try the below commands if you are stuck with an issue in Jenkins and need to start/stop in Mac

brew services stop jenkins-lts

brew services start jenkins-lts