Jenkins for Maven Project with xUnit on CentOS

Step 1: Install dev env, maven, Jenkins

sudo yum groupinstall "Development Tools"

wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo yum insatll apache-maven

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
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins

chkconfig jenkins on #start Jenkins when boot
sudo vim /etc/sysconfig/jenkins # set JENKINS_HTTPS_LISTEN_ADDRESS="0.0.0.0" to listen on all IPs for HTTPS

Step 2: Setup Jenkins
– Visit host:8080
Configure Global Security: Choose Jenkins user DB and create user. Define matrix security rules: grant only “read” to anonymous user. Disable create user.

– Configure Jenkins System: Specify paths to JDK, Maven
Plugins: install Git Plugin, xUnit Plugin

Step 3: Create a new Item, and fill in the followings
Project name
Description
Git repo and credentials
Build Triggers
– Poll SCM
Build
-Root POM: path to pom in the repo
-Goals and options: test install
Post Steps
-Process xUnit test result report: Specity JUnit Pattern as “surefire-reports/*.xml”
-Configure Failed Tests

Step 4: Trigger build from remote


curl http://jenkinshostname:8080/git/notifyCommit?url=gitpath&branches=yourbranch/HEAD

Advertisements

Configure Jenkins for a Basic Python Project

Install and set up Jenkins following the official document.

Plugins: Install Jenkins Covertura Plugin + GIT Plugin + Jenkins Violations.

Step 1: Create a new Item “py_analysis” and select “Build a free-style software project”

Step 2: Version Control. I put Git here, with repo URL and credential. I added “SSH username with private key” here. The category of credential may vary depending on users’ situation.

Step 3: Add build step – Execute shell

PYENV_HOME=$WORKSPACE/.pyenv/

# Delete previously built virtualenv
#if [ -d $PYENV_HOME ]; then
#    rm -rf $PYENV_HOME
#fi

# Create virtualenv and install necessary packages
virtualenv $PYENV_HOME
. $PYENV_HOME/bin/activate
pip install --quiet <LIBS I LOVE>
pip install --quiet pylint
pip install --quiet $WORKSPACE/project/  # where your setup.py lives
#nosetests --with-xcoverage --with-xunit --cover-package=model --cover-erase
cd $WORKSPACE/project/testPackage 
nosetests --with-xunit --cover-package=model --cover-erase -a '!slow'
pylint -f parseable $WORKSPACE/project/package | tee pylint.out

Step 4: Post-build Actions
Publish Covertura Coverage Report – Put Covertura xml report pattern as “**/coverage.xml”

Publish Unit Test Report – Put Covertura xml report pattern as “**/nosetest.xml”

Step 5: Save and build.

reference: http://bhfsteve.blogspot.ie/2012/04/automated-python-unit-testing-code_27.html