How to Build in Jenkins whenever you push your code to GitHub? (Build Pipeline)

How to Build in Jenkins whenever you push your code to GitHub? (Build Pipeline)

Prerequisites

  • The user should have installed Java in the system and should know the environment variable of Java.

  • The user should have Jenkins Installed on the Local (on-premise)

  • The user should have a time-tracker project forked in their repository.

    %[github.com/chiragkuk24/time-tracker]

  • The user should have Apache Maven installed and should know the home directory.


  1. Open Jenkins on your local and install the Maven plugin by clicking Manage Jenkins->Plugins

  2. Once you install the Maven plugin click on New Item

    Once you click on New Item you will see the below screen Enter any name (here I have given my maven project) and then click on Maven Project and click on the OK button.

  3. Once you click on the OK button you will see the below screen

  4. Now Make the changes in Source Code Management and select Git

  5. Once you select Git enter the Repository URL and credentials

    For credentials click on the Add button and enter the Username of your GitHub account and in Password enter the Token for your GitHub Account.

    Click on Add. Once you click on Add you'll see the credentials in dropdown Select the credentials.

  6. Now, we want whenever the Code gets pushed in the Git the build should start automatically. For this, we will use the Poll SCM with 5 stars which means it'll always look for a new push every minute.

  7. Now, under build for Goals and Options put clean package.

    and I want an Email Notification once the build is done. Click on Apply and Save it.

  8. Now, Come to Manage Jenkins and click on Tools Give the Home Directory of JDK installation and MAVEN Installation. Click on Apply and Save it. (Please note the path can be different for each user I am using Linux for Windows OS this path can be different. Kindly check Google/YouTube for the installation of JAVA and MAVEN and find their Respective HOME directories)

  9. Now, for the first time, Jenkins will build automatically


    1. Once it is built, Make the changes in the Github Repo README.md and let's see if Jenkins re-built it or not.

    2. Now, we will see a new Build will start

      Now, Build 2 started Automatically in Jenkins

Did you find this article valuable?

Support Chirag Kukreja by becoming a sponsor. Any amount is appreciated!