2016年9月16日 星期五

Jenkins on Ubuntu (for python project)

Goal: install Jenkins on Ubuntu 16.04, perform CI practices on two sample projects in c and python.

Steps:

  1. install Jenkins
  2. setup Jenkins
  3. select one simple project on github, make target machine (the same one with Jenkins) ready for git, python:coverage, python:nosetests
  4. setup CI, focusing on build/test/report parts
  5. summarize and define follow-up items

Reference:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu



1. Install Jenkins

wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

2. Setup Jenkins

major files

/etc/init.d/jenkins
if daemon was not started automatically, typesudo update-rc.d jenkins enable
/etc/passwd
new user "jenkins" was created by "apt-get install"jenkins:x:122:129:Jenkins,,,:/var/lib/jenkins:/bin/bash  
QQ: should we need to change to :/usr/bin/nologin
/var/log/jenkins/jenkins.log
tail -f /var/log/jenkins/jenkins.logSep 16, 2016 8:26:58 AM hudson.model.UpdateSite updateDataINFO: Obtained the latest update center data file for UpdateSource defaultSep 16, 2016 8:26:58 AM hudson.WebAppMain$3 runINFO: Jenkins is fully up and running
/etc/default/jenkins
  • 16 # user and group to be invoked as (default to jenkins)
  • 17 JENKINS_USER=$NAME
  • 18 JENKINS_GROUP=$NAME
  • .
  • 23 # jenkins home location
  • 24 JENKINS_HOME=/var/lib/$NAME
  • 31 # log location. this may be a syslog facility.priority
  • 32 JENKINS_LOG=/var/log/$NAME/$NAME.log
  • 33 #JENKINS_LOG=daemon.info
  • .
  • 56 # port for HTTP connector (default 8080; disable with -1)
  • 57 HTTP_PORT=8080
Web UI

password for first login, clues found from /var/log/jenkins/jenkins.log
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
0xxx.xxx5
This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword


3. Setup Test Machine


sudo apt-get install -y git
sudo apt-get install -y python-pip
sudo pip install nose
sudo pip install coverage 

4. Setup Jenkins Project


Jenkins -> New Items

GitHub Project Setting

SCM Setting


Build Triggers (not yet find a suitable configuration)

Build and Post-build Actions (test coverage report)

5. Summarize and Define Follow-Up Items

Project kata-demo

Build History

Status -> Build# -> Console Output

Coverage.py Report

Follow-Up Items

  1. How to integrate Jenkins with Sonar Cube
  2. How to update comment to GitHub commit
    • Post-build Actions -> Set status for GitHub commit



x. Check Service Manually if necessary
$ sudo netstat -tupln | grep 8080tcp6  0  0 :::8080  :::*  LISTEN  1338/java 
$ ps -ef | grep jenkins
  • jenkins    1328      1  0 08:26 ?        00:00:00 /lib/systemd/systemd --user
  • jenkins    1330   1328  0 08:26 ?        00:00:00 (sd-pam)
  • jenkins    1337      1  0 08:26 ?        00:00:00 /usr/bin/daemon --name=jenkins --inherit --env=JENKINS_HOME=/var/lib/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/jenkins/jenkins.pid -- /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
  • jenkins    1338   1337  1 08:26 ?        00:00:31 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080



沒有留言:

張貼留言