Create webhook for the app in github
By creating webhook in github app repository and connecting it with jenkins, make sures whenever you make any changes in the code in github, it automatically triggers and starts building the pipeline.
Go to app repository in github and click on settings
Select Webhooks > click on Add Webhook
Now enter the jenkins URL in the below format and check the appropriate event and click on Update webhook making sure you have kept a check on Active
http://<Jenkins URL>:8080/github-webhook/
Now check whether the connection is established with a ✅ sign
Now go to Jenkins, select create a Job by selecting pipeline, enter the github repository where the code is saved and also check on GitHub hook trigger for GITScm polling.
Create SCM polling
SCM polling by default is present in jenkin which is use to detect jenkinsfile present with code in github repository. So no need to write any groovy script in jenkins.
Create a job. Enter the project name and select pipeline.
In the configuration of the job after entering github repository and trigger type scroll down to Pipeline, click on drop box and select Pipeline script from SCM.
Enter the github repository URL where jenkinsfile is present. It will automatically search for jenkinsfile in the github in master branch
The name can be different as well not necessarily Jenkinsfile. You may keep a different name where pipeline script is written. Below in the Script Path, it is Jenkinsfile which it'll be searching in github repository which is provided.
After saving the configuration Build the job and it will start building the pipeline script which is written in Jenkinsfile.