Popular Triggers :-
Git Webhooks
Poll SCM
Schedule jobs
Remote Triggers
Build after a particular job
Many more.....
Basic steps to follow are :-
Create a GitHub repo.
Generate SSH keys from your terminal by command(ssh-keygen).
Save the public key in GitHub SSH keys you can find it in the github settings.
Create a JenkinsFile in Git repo and commit it.
Go to your Jenkins Server and create a pipeline job.
In the configure section of the job, click on script from SCM.
In this input your GitHub repo SSH URL, Credentials such as UserName and ssh private key, Github account.
In the script from SCM input your github Branch where your JenkinsFile is stored.
Save the settings and click on Build now.
Test your triggers
Take Care Of :-
Jenkins server is allowing TCP access from anywhere 0.0.0.0/0 .
Host Key Verification - Choose Accept first connection from the options.
Git Webhooks :-
You can use this when ever you want to trigger the Jenkins Job for a certain action happened on your GitHub repo.
Go to the settings of your GitHub repo -> Webhook.
Put the URL - Like "<URL>/github-webhook/" ,Content type, Action on which you want the trigger to run the job.
Please take the note that Jenkins server should allow the ssh connection from anywhere.
Poll SCM :-
Just follow the URL saving steps.
After choosing pipeline, select the option Poll SCM.
Now input the time at which you want to run the job. Just like you do in CRON job.
Schedule Jobs :-
- It is the same as of poll SCM.
Remote Triggers :-
This is one of the coolest triggers out there because you can run for job from anywhere like from a script,your laptop,jenkins sever etc.
You need 4 things for this and that are :-
Job URL with Token - USERNAME:API_TOKEN
Token - Jenkins -> Build Triggers -> Triggers Build remotely -> generate and copy.
CRUMB - For this download wget command from the browser 64-bit zip file. eg:- Jenkins-Crumb:dv98dnke985345n3bhdkjhkh53ifindiw535bi5i3b23
CURL command :- curl -I -X POST http://username:APItoken @Jenkins_IP:8080/job/JOB_NAME/build?token=TOKENNAME -H "Jenkins-Crumb:CRUMB"
When you will run the Curl command your job will get triggered.