Triggering a Jenkins build

Few common ways out many ways to manual and automatic build creation on Jenkins are:

Manual Build:

 

Polling the repository:

Now, it is possible to setup a Build Trigger to get Jenkins to poll for changes in a Git repository. You do this using the Poll SCM option on the project configuration page in Jenkins. * * * * * means it will poll every minute for new commit changes. If changes found then it will create a build.

By enabling Poll SCM and entering a cron expression * * * * * in the Schedule text box we can get Jenkins to poll the repository for changes every minute. You can enter whatever cron expression you like but this serves as a simple example.

Polling the repository is a bit ugly and inefficient. Wouldn’t it be better to get Git to notify Jenkins of a commit and to trigger a build that way? Well you can do just that using ‘Git hooks’.

Triggering a build using Git hooks:

Inside every Git repository there’s a hidden .git folder. Inside the .git folder is a hooks subfolder. This folder can hold scripts that are executed by Git when it performs certain operations. I’m not going to delve into Git hooks here.

Github WebHooks:

Whenever code is committed. Github hook will notify Jenkins and build will get started. For this setting you can got to your github/bitbucket project –> setting –> WebHooks –> Add new webhook. Give your Jenkins URL like https://USERNAME:PASSWORD@jenkins.example.com/github-webhook/

OR

http://jenkins.example.com/github-webhook/

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *