Hello World from OSS Silicon Valley


HowToUse/Jenkins/1.594

_ Prerequisite

_ Install&Setup

_ Install Jenkins

Step.1
Import public key.
# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
# rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
Step.2
Install Jenkins
# yum install jenkins

_ Launch Jenkins

Step.1
Login from GUI with root.
Step.2
Select System -> Administration -> Firewall
Launch_fig1.png
Step.3
Select "Other Ports" and click "Add" button and set 8080 port.
Launch_fig2.png
Step.4
Click "Apply" button on the "Firewall Configuration" window.
Step.5
Execute the following command and access http://<host name>:8080/.
# /etc/rc.d/init.d/jenkins start
Launch_fig3.png

_ HowToUse

_ Prepare maven project

Step.1
Prepare workspace in your pc.
# svn checkout <SVN repository path>
Step.2
Create Maven project.
$ cd <project directory>
$ mvn archetype:create \
 -DgroupId=<Group ID> \
 -DartifactId=<Artifact ID>
Step.3
Edit POM.xml so that maven create Javadoc.
# vi pom.xml
 <build>
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-javadoc-plugin</artifactId>
       <configuration>
         <author>true</author>
         <source>1.7</source>
         <show>protected</show>
         <encoding>UTF-8</encoding>
         <charset>UTF-8</charset>
         <docencoding>UTF-8</docencoding>
       </configuration>
     </plugin>
   </plugins>
 </build>

Or you can get sample files from the Github - OSSSV

Step.4
Check in files into the repository Jenkins will monitor.
# svn add .
# svn commit -m "Import new files"

_ Mail Server Configuration

Step.1
Click "Manage Jenkins".
ServerConfig_fig1.png
Step.2
Click "Configure System".
ServerConfig_fig2.png
Step.3
Setup mail notification configuration.
ServerConfig_fig3.png
ItemDescriptionExample
SMTP serverSMTP server"smtp.gmail.com"
Default user e-mail suffixIf you specify this as "@gmail.com", user e-mail address will be automatically obtained as <user name><suffix>@gmail.com (for gmail)
Step.4
Click "Advances..." button. Setup the configuration.
ServerConfig_fig4.png
ItemDescriptionExample
Use SMTP AuthenticationIf you expect SMTP authorization, check thisTRUE (for gmail)
User Namee-mail user name for SMTP authentification"syatsuzuka"
Passwordpassword for SMTP Authentification"xxxx"
SSLif SMTP server require SSL, check thisTRUE (for gmail)
SMTP PortPort used in SMTP server"465" (for gmail)
CharsetCharacter used in e-mail"UTF-8"

_ Install JDK for Jenkins

Step.1
Click "Manage Jenkins" link.
Step.2
Click "Configure System" link.
Step.3
Click "Add JDK" button.
Step.4
InstallJDK_fig1.png
ItemDescriptionExample
NameJDK name"jdk8u25"
Install automaticallyIf you want to install JDK automatically, keep this checkedTRUE (default)
VersionJDK Version"Java SE Development Kit License Agreement
I agree to the Java SE Development Kit License AgreementTRUE
Step.5
Click "Please enter your username/password" link.
Step.6
Enter Oracle account and click "OK" button.
InstallJDK_fig1.png

_ Install Maven for Jenkins

Step.1
Click "Add Maven" button and set Name.
Step.2
Click "Save" button.

_ Create Items for Build

Step.1
Click "New Item" link.
CreateItem_fig1.png
Step.2
Set "Item name", check "Freestyle project" and click "OK" button.
ItemDescriptionExample
Item nameItem name"sample"
CreateItem_fig2.png

Now, you have new directory named "sample" in JENKINS_HOME, namely, /var/lib/jenkins. Resources which are necessary for build will be stored in workspace.

Step.3
Click Subversion for "Source Code Management" and set "Repository URL".
ItemDescriptionExample
Repository URLRepository URL"http://localhost/svn"
CreateItem_fig3.png
Step.4
Click "enter credential" link.
CreateItem_fig4.png
Step.5
You can choose build trigger according to your situation.
  • "Build after other projects are built"
  • "Build periodically"
  • "Poll SCM"

Here, I choose "Poll SCM". Check "Poll SCM". If you want to check every 5min, set as follows. The order of parameters are same as cron.

min hour day month wday

H/5 * * * *
CreateItem_fig5.png
Step.6
Select "Invoke top-level Maven targets" from "Add build step".
Step.7
Set the following.
ItemDescriptionExample
Maven Versioninstalled maven version"maven3.2.2"
goalmaven goal"compile"
CreateItem_fig7.png
Step.8
Click "Advanced ..." link and set as following.
ItemDescriptionExample
POMfile path to the pom.xml in the workspace"trunk/sample/pom.xml
Step.9
Click "Save" button. Now, you can see New Item in the main window.
CreateItem_fig6.png

_ Run Build

Step.1
Click newly created "sample" link.
Step.2
Click "Build Job" link and you can see the status of job is changed.
Step.3
For your first job, Jenkins will download and install maven and related libraries, so it takes time. After the build job finished, you can check test result.

You can see the detail information from terminal log, Jenkins -> sample -> #<job number> -> "Console Output Windows".

RunBuild_fig1.png

_ E-mail notification setting

Step.1
It is useful to notify error by notification mail. Select target Item and click "Configure" link. Then choose "E-mail Notification" from "Add post-build action" and set "Recipients".
ItemDescriptionExample
Recipientsrecipients of error notification"syatsuzuka@xxx.org"
Email_fig1.png

After saving, you will recieve notification mail when you encounter error in build.

_ JUnit Testing

Step.1
Jenkins can display JUnit test report. Select target Item and click "Configure" link. Then choose "Publish JUnit Test Result" from "Add post-build action".
ItemDescriptionExample
Test report XMLsSpecify the location of JUnit result report file"trunk/sample/target/surefire-reports/*.xml"
Step.2
Add "test" to maven goal.
ItemDescriptionExample
goalmaven goal"compile test"

After saving, you can see test result in Jenkins window.

JUnit_fig1.png
JUnit_fig2.png
JUnit_fig3.png

_ Javadoc creation

Step.1
Jenkins also can show Javadoc from its window. Select target Item and click "Configure" link. Then choose "Publish Javadoc" from "Add post-build action".
ItemDescriptionExample
Javadoc directorydirectory path Javadoc will be stored"trunk/sample/target/site/apidocs"
Step.2
Add "javadoc:javadoc" to maven goal.
ItemDescriptionExample
goalmaven goal"compile test javadoc:javadoc"

After saving, you can see javadoc link in your build result page.

Javadoc_fig1.png

_ Deploy objects

Step.1
Click "New Item" link.
Step.2
Set "Item name", check "Freestyle project" and click "OK" button.
ItemDescriptionExample
Item nameItem name"sample.deploy"
Step.3
Select "Build after other projects are built".
ItemDescriptionExample
Projects to watch"sample"
Step.4
Click "Execute shell" from "Add build step" to deploy the created files. Here, I use dummy program, "deploy_files.sh" for deployment.
ItemDescriptionExample
Commandcommand line"echo deploy started >> /tmp/jenkins.log"
Step.5
Set e-mail notification same as "sample".

_ Setup User Security

Step.1
Click "Mange Jenkins" link and "Setup Security".
SetupSecurity_fig1.png
Step.2
Click "Enable security" and "Jenkins'own user database".
ItemDescriptionExample
Security RealmChoose how to refer security definition"Jenkins' own user database"
AuthorizationChoose authorization management"Matrix-based security"
SetupSecurity_fig2.png
Step.3
Sign up the user.
Step.4
If you set readonly for "anonymous", guest user cannot execute "build" any more.
SetupSecurity_fig4.png

_ Author

S.Yatsuzuka

Last-modified: 2015-08-17 (Mon) 02:41:34 (3168d)