Continuous Build with Jenkins on Windows with Tomcat, github, Ant and Eclipse
Continuous Build with Jenkins with Tomcat, github, Ant and Eclipse
A quick look at setting up a Jenkins job to automatically build and deploy a Dynamic Web Project.
For Windows here is what you need:
Start Jenkins
java -jar jenkins.war
Visit http://localhost:8080/ to access Jenkins
Install Jenkins as a service
Instructions are here:https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service
Jenkins running on http://localhost:8080/
Add github support to Jenkins
Manage Jenkins
Under the github section provide the path to git.exe
github section:
Git Plugin section:
Global Config user.name Value {Your git username}
Global Config user.email Value {email address}
SSH keys
Generate ssh keys using C:\dev\Git\bin\ssh.exe
Store the generated keys in the following folder:
C:\Documents and Settings\{username}\ssh
Add them to github.com
See my previous post http://straightforwardit.blogspot.com/2011/11/setting-up-eclipse-for-github.html
Setup email notifications, using gmail
In the E-mail Notification section, add the following
SMTP Server:smtp.gmail.com
Sender e-mail address:{username}@gmail.com
Click Use SMTP Authentication
Username:{username}@gmail.com
Password:{gmail pass}
Click Use SSL
SMTP Port 465
Confirm by using the Test configuration by sending test e-mail option
Adding plugins to Jenkins
Manage Jenkins\Manage Plugins\Available
Add the following plugins:
Scroll to the bottom and Click install
View of installed plugins:
Create a Dynamic Java Project
See https://github.com/sfbishop/TestProject for a reference
Creating a New Job
In Maven's menu Click New Job
Provide a job name
Use a Build a free-style software project
Configuring the Job Options
Under the Source code Management section
Pulling code from gitbub
Click the git button
Enter you repository url, something like: git@github.com:{git username}/TestProject.git
Calling Ant
In the build section, click the Add Build Step button, select Invoke Ant
Provide the Targets to run in a commas separated list
example: compile test
Post-build actions
Check the Publish JUnit test results report
Test report XMLs: TestProject/build/testreports/*.xml
Check Retain standard output/error
Deploying to Tomcat, automatically
In the Post-build actions section
Check Deploy war/ear to container
WAR/EAR files:**/*.war
Container: Tomcat 7.x
Manager user name: tomcat
Manager password: {password}
Tomcat url: http:localhost:8787
Sending email notification on failure
Check Email-notifications
Enter your email address
Check Send e-mail for every unstable build
Building your project
From the Jenkins dashboard, click on the project name
Click Build Now on the left hand side
Select the Build from the Build history section
Select Console output to view the build information
If everything is successful you should see a Jenkins blue ball next to the build number
Build History Section:
Things to watch out for:
A quick look at setting up a Jenkins job to automatically build and deploy a Dynamic Web Project.
For Windows here is what you need:
- Tomcat or another web container
- Ensure the default ports are changed, for my examples I used 8787 for tomcat
- Tomcat is installed and running
- Eclipse with a github plugin
- see my previous post http://straightforwardit.blogspot.com/2011/11/setting-up-eclipse-for-github.html
- You have a Java project checked into github.com
- If not, https://github.com/sfbishop/TestProject is accessible
- A github account (see github.com)
- Remember to setup the SSH keys
- Jenkins (see http://jenkins-ci.org/)
- Download the lastest war file
- github client software
Start Jenkins
java -jar jenkins.war
Visit http://localhost:8080/ to access Jenkins
Install Jenkins as a service
Instructions are here:https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service
Jenkins Service installed:
Jenkins running on http://localhost:8080/
Add github support to Jenkins
Manage Jenkins
Under the github section provide the path to git.exe
github section:
Git Plugin section:
Global Config user.name Value {Your git username}
Global Config user.email Value {email address}
SSH keys
Generate ssh keys using C:\dev\Git\bin\ssh.exe
Store the generated keys in the following folder:
C:\Documents and Settings\{username}\ssh
Add them to github.com
See my previous post http://straightforwardit.blogspot.com/2011/11/setting-up-eclipse-for-github.html
Setup email notifications, using gmail
In the E-mail Notification section, add the following
SMTP Server:smtp.gmail.com
Sender e-mail address:{username}@gmail.com
Click Use SMTP Authentication
Username:{username}@gmail.com
Password:{gmail pass}
Click Use SSL
SMTP Port 465
Confirm by using the Test configuration by sending test e-mail option
Adding plugins to Jenkins
Manage Jenkins\Manage Plugins\Available
Add the following plugins:
- "Deploy to container Plugin"
- "Jenkins GIT plugin"
- "GitHub plugin"
Scroll to the bottom and Click install
View of installed plugins:
Create a Dynamic Java Project
See https://github.com/sfbishop/TestProject for a reference
Creating a New Job
In Maven's menu Click New Job
Provide a job name
Use a Build a free-style software project
Configuring the Job Options
Under the Source code Management section
Pulling code from gitbub
Click the git button
Enter you repository url, something like: git@github.com:{git username}/TestProject.git
Calling Ant
In the build section, click the Add Build Step button, select Invoke Ant
Provide the Targets to run in a commas separated list
example: compile test
Post-build actions
Check the Publish JUnit test results report
Test report XMLs: TestProject/build/testreports/*.xml
Check Retain standard output/error
Deploying to Tomcat, automatically
In the Post-build actions section
Check Deploy war/ear to container
WAR/EAR files:**/*.war
Container: Tomcat 7.x
Manager user name: tomcat
Manager password: {password}
Tomcat url: http:localhost:8787
Sending email notification on failure
Check Email-notifications
Enter your email address
Check Send e-mail for every unstable build
Building your project
From the Jenkins dashboard, click on the project name
Click Build Now on the left hand side
Select the Build from the Build history section
Select Console output to view the build information
If everything is successful you should see a Jenkins blue ball next to the build number
Build History Section:
Things to watch out for:
- Ant paths, since they will be running under the jobs directory try not to hard code any absolute paths
- ssh keys with github
- Ports, ensure Web Container and Jenkins aren't using the same port.
Comments
Post a Comment