Sunday, January 20, 2013

Udemy Jenkins Bootcamp: Fully Automate Builds Through Deployment

1- firstly we installed GIT to use it.
some important instruction in GIT
- you need to set some global variables to git like your username and email
 git config --global user.email "hassan.jamous@gmail.com"
6- 
- and you can check your global variables:
git config --global --list

2- we installed jenkins in windows from jenkins installer, you have a jenkins service in windows to stop and start jenkins

3- jenkins comes with alot of plugin, however you should update these plugins after installation

from the dashboard go to manage jenkins, then manage plugins, from here select all the plugins and press update, restart jenkins when you finish.

4- you can download plugin ( like a plugin that change the sucess build ball color from blue to green ) from the first page (manage jenkins)

5- you can delete a build however you should not

6- from the dashboard choose Manage Jenkins then Configure System, this is an important page where you set jenkins configuration.
you should provide jenkins with the JDK path and the Maven path, you add them in this page.


7- another important git command
git clone https://github.com/srctips/time-tracker.git
which we use it to clone the project to local disk

8- in order to use git and github in Jenkiens you should add them
go to Manage Jenikns then manage plugins, add "git plugin" and "github plugin"

now you can find 2 section one for git and another for github in ManageJenkins->configure System

Create a Project with Maven and github
first you create a new job and you select Maven project

then on the next page you set the github project url

the project URL is the url in the browser:


then ( on the same page ) you set the "Source Code Management" to git


set Credentials to none ( as this is a public repository ), the Repository URL can be taken from here

after you run the project you will notice that you have Modules section to the lift of the project, Jenkins understand the Modules in POM.xml
and in the build section you should specify the pom.xml



you can set also the Build Trigger

Build periodically: you set a time like build every 5 minutes
Poll SCM: you can poll the source control every 5 minutes for example to check if there is any change, if yes create a build
Build when a change is pushed to GitHub.

/////////////////////////////////////////////////////////

you can create a new view in Jenkins, if you have many project in the home page, you can create a view with some project

simply press the + button
///////////////////////////////////////////

Jenkins and Testing
1- ensure that JUnit plugin is installed
2- install checkStyle plugin
3- install FindBugs Plugin: it gives statistics about bugs in java code
4- install PMD Plugin: it gives information about java code, like unused variables.

now go to job configuration
you will find this

the advanced option will give you more things like fail the build based on the number of errors and so on, like fail if there are more than 90 style errors.

/////////////////////////////////////////////////////////////////

Publish Artifacts
what we will do here is to build our Maven project so other process can use it as a dependency,

1- download "Maven Repository Server" plugin and install it
2- go to the job configuration you will find this section:

now when you build the project and you open the build you will find "Build Artifacts As Maven Repository"


when you open it you will find information about the maven project and you willl find the SnapShot

////////////////////////////////////////////////////////

Jenkins & Deploy to  TOMCAT

1- after you install TOMCAT, go to conf/tomcat-users and add the following user
  <user username="jenkins" password="jenkins" roles="manager-script"/>
notice the role is manager-script
restart tomcat
now to check if the user is working go to    
localhost:TOMCATPORT/manager/text/list
and use the jenkins user name and password

you should be able to login and see a list of running applications


2- download the "Deploy to container Plugin" in jenkins

3- now go to the job configuration and change the "post-build actions" to "deploye war/ear to container"


fill the information, **/*.war means any war file in the directory, we also field the user information.

now when you build the job it will deploy it to tomcat.


Jenkins Security
when we install Jenkins, it will be installed with security enabled is off, which means anybody with the link can access jenkins.
to enable security
1- go to Manage Jenkins then Configure Global Security,
2- check Enable security checkbox
3- set "jenkins owns user database"
4- set "logged-in users can do anything"


you can also create users and roles, using the option Matrix-based security or Project-based Matrix Authorization Strategy.

however to enable users and roles in a nicer way, download this plugin:Role-based Authorization Strategy
now if you go to Configure Global Security, you will find a new option which is  Role-Based Strategy

check this option,
now if you go to Configure Jenkins, you will find a new option "Manage and Assign Roles" here you can create roles and assign them to users.

Also you can create users from Configure Jenkins, Manage Users.



No comments:

Post a Comment