Jenkins Triggers

Jenkins Triggers

  • Git Webhooks

  • Poll SCM

  • Schedule jobs

  • Remote Triggers

  • Build after a particular job

  • Many more.....

Basic steps to follow are :-

  1. Create a GitHub repo.

  2. Generate SSH keys from your terminal by command(ssh-keygen).

  3. Save the public key in GitHub SSH keys you can find it in the github settings.

  4. Create a JenkinsFile in Git repo and commit it.

  5. Go to your Jenkins Server and create a pipeline job.

  6. In the configure section of the job, click on script from SCM.

  7. In this input your GitHub repo SSH URL, Credentials such as UserName and ssh private key, Github account.

  8. In the script from SCM input your github Branch where your JenkinsFile is stored.

  9. Save the settings and click on Build now.

  10. 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 :-

  1. You can use this when ever you want to trigger the Jenkins Job for a certain action happened on your GitHub repo.

  2. Go to the settings of your GitHub repo -> Webhook.

  3. Put the URL - Like "<URL>/github-webhook/" ,Content type, Action on which you want the trigger to run the job.

  4. Please take the note that Jenkins server should allow the ssh connection from anywhere.

Poll SCM :-

  1. Just follow the URL saving steps.

  2. After choosing pipeline, select the option Poll SCM.

  3. 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.

Did you find this article valuable?

Support Saurabh's blog by becoming a sponsor. Any amount is appreciated!