Wednesday, May 20, 2015

Experimenting with Jenkins, ReviewBoard, and Redmine on Azure

As the developers at work finished up the last loose ends on the Programming Standards we were tasked with creating at work, one of the last things we talked about was how to enforce the standards.  This led to a discussion of code reviews, and I went down the rabbit hole, going so far as to read SmartBear's free 150 page ebook on the subject.  I thought it was a great approach but it seemed that in order to really get the most out of it, you needed a tool.  I wanted to play around with something, so I began looking into what was available for free, and ended up going down a bit of a different rabbit hole: continuous integration.  I wanted to see how Jenkins, ReviewBoard, and Redmine could work together to act as a suite of tools for agile development.  So I spun up some Ubuntu 14.04 instances on my Azure account, and away I went...

Note on Azure

All of the servers (jenkins, reviewboard, redmine) need to have ports open for in order for them to be accessed via the web. These are configured through Settings > Endpoints

Jenkins


Install when super smooth, just followed this guide:
https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu

Will build on Github push with a hook. Important points:

1.  Using unix user/groups for security and hook needs an identity, so created a “github” user with “nologin” for shell and generic password (“notasecret”):
passwd entry:   Github:x:1001:1001::/home/Github:/usr/sbin/nologin
http://fourword.fourkitchens.com/article/trigger-jenkins-builds-pushing-github
http://www.cyberciti.biz/tips/howto-linux-shell-restricting-access.html

2. Requires “content type” be form encoding on the Github side:

I wanted Jenkins to create a review on ReviewBoard as part of the build.  I did this by executing a shell scripts using RBTools to post a review request to ReviewBoard.
https://www.reviewboard.org/docs/rbtools/0.7/rbt/commands/post/#automating-rbt-post

Doing this requires that the .reviewboardrc file be present in the “workspace” directory for that project. In Ubuntu this lives in /var/lib/jenkins/jobs/<name>/workspace

Used grep to extract an email address from commit log, use in --submit-as so that reviews appear to be submitted by person committing rather than by jenkins

Jenkins needs his own ReviewBoard account so he can submit new reviews on commit. This account needs “can edit review request” and “can submit as another user” permissions.

I did quite a bit of experimenting with the script for reviewboard. What I finally concluded was that if I was on the master branch, I wasn’t going to get a diff automatically and trying to manually generate one was getting me nowhere fast. This was due to the fact that rbt generates the diff by comparing the commit to master… so if you are on master, oops, up to date, no diff ~:[ … blew up about 16 builds trying to get it right before I finally decided I was thrashing. Here is what my script looks like now:

#BUILDNO=$(ls "/var/lib/jenkins/jobs/test item/builds" | egrep -o '[0-9]*' | sort -n | tail -1)
#COMMITER=$(grep -oP '(?<=(push.by.)).*' /var/lib/jenkins/jobs/test item/builds/$BUILDNO/log)
#cd "/var/lib/jenkins/jobs/test item/workspace"

cd "$WORKSPACE"
COMMITER="`git log --name-status HEAD^..HEAD | grep -m 1 Author: | grep -Po '(?<=\<)(.*)(?=\>)'`"
REVIEWID="`git log --name-status HEAD^..HEAD | grep -Piom 1 '(REVIEW#|RBID#|RID#|REVIEWID#)\K\d*' || echo -n ''`"
#GITBRANCH=`git rev-parse --abbrev-ref HEAD`

if [ $REVIEWID > 0 ]; then 
    REVIEWPARAM="-r $REVIEWID"
else 
    REVIEWPARAM="-g"     
fi

#if the diff is blank, then compare to previous commit
DIFFSIZE="$(rbt diff | wc -m)"
if [ $DIFFSIZE = 0 ]; then
    echo "No diff, skipping reviewboard push"
    #echo No automatic diff, creating from commits
    #git diff HEAD^..HEAD > diffs
    #rbt post -p --username=jenkins --password=jenkins --submit-as=$COMMITER --diff-filename diffs
else
    echo Diff generated automatically
    rbt post -p $REVIEWPARAM --username=jenkins --password=jenkins --submit-as=$COMMITER
fi

using Jenkins to set Github build statuses might be fun…
http://stackoverflow.com/questions/14274293/show-current-state-of-jenkins-build-on-github-repo/26910986#26910986

I might need to use “expect” on future scripts
http://stackoverflow.com/questions/14670716/simulate-user-input-in-bash-script

ReviewBoard


Touchier to get installed than Jenkins, key was installing Apache and Mysql first, making sure they were fully functional, THEN installing ReviewBoard.

Once apache was running and verified (azure ports opened), the rest of set up was a breeze. python-setuptools did most of the heavy lifting.

https://www.reviewboard.org/docs/manual/2.0/admin/installation/linux/

Redmine


Redmine was the most difficult to install and configure. Many dependencies and multiple ways to actually install. Didn’t help that there were multiple guides of varying age targeting several flavors of Linux (and even different version of Ubuntu…)

Ruby in general gave me a lot of trouble. Tried an install with RVM which may or may not have helped.

I installed with MySql, but missed libmysqlclient-dev.  Also missed ruby-dev, which prevented it from building extensions… and I missed build essentials (and thus didn’t have make)... RMagick also gave me a headache.  Even once everything was installed, wasn’t obvious that I had to add the mysql connector gem to the “gemfile”.  Permissions were very finicky… took forever to get ownership and permissions just right so that everything would play together.

Getting the repository set up, and playing nice with the github plugin, was a nightmare. Finally was able to get it to work when I cloned the repo as a mirror (should it really be that hard??). I kept getting the dreaded 404 error, and even after I got that figured out, git was having a fit throwing a fatal error because the repo wasn’t bare.

Phusion Passenger gave me some trouble, mostly related to permissions and ownership

webhook with Github was pretty painless once the repo on Redmine was setup right. Had to specify the project_id and repository_id since nothing matched the github repo name...

http://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_on_Ubuntu_step_by_step

http://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_25x_on_Ubuntu_1404_with_Apache2_Phusion_Passenger_MySQL_and_Subversion

NOTE: This is WAAAAAY easier if you use the bitnami stack… except make sure you use the 64 bit version… and not redmine 3.x, none of the plugins are compatible… Ugh I never could quite get the bitnami version to cooperate. I had to leave off for a bit and work on other stuff, I was at the “I’m going to throw shit out the window” level of frustration. To be continued...

No comments:

Post a Comment