Showing posts with label jenkins. Show all posts
Showing posts with label jenkins. Show all posts

Integrate Jenkins with github and Automatically kick off Jenkins when new build is pushed to git hub


Integrate Jenkins with github and 
Automatically kick off Jenkins when new build is pushed to git hub:


Get web hook url from Jenkins.
Go to Jenkins
Click manage Jenkins
Click Configure system
Go to GitHub Plugin Configuration
Click Advanced
Check specify another hook url for github configuration
Copy the hook url and uncheck the check box
Go to github repository
Go to settings
Click Webhooks and services
In webhook section, click Add webhook
Paste the url to the Payload URL
Now, select Which events would you like to trigger this webhook?
Everything or every push or select other events from the options such as Dev team push then kick off the execution.
You can also select content type
You can leave the active checked
Click Add webhook
Now, go to Jenkins
Click a jenkin job
Click configure
In build triggers section, check Build when a change is pushed to Github
Click Save

Push to Github
Cmd prompt
Git status --- to know the status
Git commit –am “comment”
Git push
Execution starts in Jenkins

Integrate Jenkins with github:
Go to Jenkins
Click manage Jenkins
Manage plugins
Click tab available
Search github
Check github integration plugin
Click download now and install after restart
This download the plugin, download other dependencies as well
Check restart Jenkins when installation is complete
Now go to git hub
Go to your repository and copy the URL
Create job in Jenkins:
Click new item
Give job name
Select freestyle project. You can select pipeline also
Click ok
In general tab , check github project
Paste the URL  of the project copied above
Scroll down, In source code management section check the radio button GIT
You have to paste another URL to Repository URL, this you got from github-clone or download button
Mention the branch in which you want to build. Default is master
Scroll down to build triggers
Check which trigger is suitable for your purpose. I am selecting GitHub hook trigger for GitScm polling
There are other options as well if you need.
Click save

Jenkins: Create job, schedule job, send email notification



Configure Email-Jenkinds Notification:
Click Manage Jenkins
Click Configure Systems
Go to Email Notification section
Give the SMTP server name for example, for gmail: it is smtp.gmail.com
Check the box "Use SMTP Authentication"
Click Advanced - give username and password. username will be the email from which the email will be sent.
check "Use SSL". Make sure if you need to check this box or not depending upon your email.
Give the SMTP port
Give the email address at Reply-To Address
Give charset as UTF-8
Test the email configuration by checking - test config by sending test email. You give the receipent email address here.
click Apply and Save
Incase you get trouble getting email from jenkins , then open your email, go to my account, go to signing into google(for gmail), Turn on the Allow less secure app

Send Email:
Go to any jobs
Go to configure
Click Add post build action
Click Email Notification
add receipient email -- this will email to this address if email fails
Click Apply and Save
Now to run, click Build Now
To change the command, click the job and click configure
When the test case fails and you get email, you can click the link in the email which will take you to the jenkins site where you can click console output to see the log.
You can add plugins to send email notification in Json and XML format


Craete new job:
Click New item
Give name, check radio Freestyle project and click OK
Click drop down Add Build Step and click Execute Windows batch command
inside Build type below command:
java -version: This will give java version , simple code for the example purpose. This is cmd command or .bat command.

Schedule jobs:
Open the job
Click Configure
in Build Triggers section, click Build Periodically
For the scheduling commands(called cron pattern) , click help and get from there. There are examples also in the help.
Online resource: wikipedia has good explanation of the cron pattern.
To run at 7pm and 15 min: 15 19 * * *, 8 pm : H 20 * * *
after you write the cron pattern, click Apply and Save
And the execution starts.