Automated Play Framework Testing with Jenkins
Jenkins automates builds and tests. This post describes setting up Jenkins for the Play 2 Framework.
First off, you need a machine with a good amount of resources. I tried first on a small cloud machine with 2GB of RAM and it was not sufficient, so get a machine with 4GB of RAM.
Next you need to install Java and SBT. Also, git if you use it for source control.
sudo add-apt-repository ppa:webupd8team/java
echo "deb http://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-get update
sudo apt-get install git oracle-java8-installer sbt
Now that you have Java installed, you can install Jenkins:
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
To be able to have Jenkins check the source code out of GitHub or BitBucket, you need to setup an SSH deploy key. First create an SSH key:
sudo su jenkins
ssh-keygen -t rsa
$ cat /var/lib/jenkins/.ssh/id_rsa.pub
Copy the key into GitHub/BitBucket as a deploy key.
Accept the remote host as a machine to trust connections to:
ls-remote -h git@host:org/repo.git HEAD
Now go to the Jenkins web UI. First, Install Jenkins GIT plugin and Jenkins sbt plugin.
Then, setup the system configuration under “Manage” > “Configure System”. Point the sbt plugin to the launcher jar we installed earlier at /usr/share/sbt/bin/sbt-launch.jar
.
You’ll also want to set some type of notification of failed builds. Set the “System Admin e-mail address” under “Jenkins Location”, which will be the email address you will receive alerts from and set the SMTP host, username, and password under “E-mail Notification”. I recommend installing the Email Extension Plugin in order to be able to customize the emails that you’ll receive. You can then set project to use Editable Email Notification as a Post-build Action. With the Email Extension Plugin, you’ll need to choose Advanced Settings… and then select Recipients or else your emails won’t go to the recipients you’ve specified. This frustrating option should not exist let alone be unselected by default. To include the build log in the email you can add ${BUILD_LOG,maxLines=10000}. I also suggest adding a trigger so that you get notified both on failed builds and also when the build is fixed.
At this point, you can create a “New Job” selecting “Build a free-style software project”. Enter your git repo location, how often to build, and set it to build with sbt. Enjoy!
Leave A Comment