- Jianfeng Chen (jchen37): Build AWS EC2, install Jenkins;
- Jianbin Chen (jchen45): Record video, write README;
- Zhewei Hu (zhu6): Config Jenkins and GitHub, write README.
We built a demo rails application used to do version control and triger git hook. You can find the repository here.
At first, we built an AWS EC2 instance and installed Jenkins on it.
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 sudo service jenkins start curl http://localhost:8080
Remember Jenkins uses the port 8080 by default, so we need to open this port. You can access our server now (username:
In order to let Jenkins do continuous integration with GitHub, we installed Git on AWS EC2 (
sudo apt-get install git). Git installation is quite easy, however, at very beginning we did not install Git and an error happened (Jenkins could not run git).
Set Git Executable Path
After installing Git, we need to set the git path in Jenkins. For Jenkins verion 2.7.4, we set the path by going through
Manage Jenkins >Global Tool Configuration > Git> Path to Git executable.And you can always find the path of Git on your machine by typing
which git. (Reference: http://stackoverflow.com/questions/8639501/jenkins-could-not-run-git)
trigger a build in response to a git commit via a git hook.
execute a build job via a script or build manager
#!/bin/bash sudo apt-get update sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 \curl -sSL https://get.rvm.io | bash -s stable --ruby source /var/lib/jenkins/.rvm/scripts/rvm ruby -v gem install rails -v 4.2.6 rails -v git clone firstname.lastname@example.org:DevOps-Milestones/m1_demo_rails_project.git cd m1_demo_rails_project/ bundle install rake db:migrate RAILS_ENV=test cp config/secrets.yml.example config/secrets.yml rake test
determine failure or success of a build job, and as a result trigger an external event
If build job is successful, you will see the console output similar to below, which means all the test cases are passed.
# Running: .............. Finished in 0.333464s, 41.9836 runs/s, 77.9695 assertions/s. 14 runs, 26 assertions, 0 failures, 0 errors, 0 skips No emails were triggered. Finished: SUCCESS
If the build fails, Jenkins will send email to all developers, which contains all failure information.
multiple jobs corresponding to multiple branches
track and display a history of past builds
Other Config of Jenkins and GitHub
- We built a freestyle Jenkins project named Milestone-rails-project-master. We chose this project is a GitHub project and pasted the corresponding URL (https://github.ncsu.edu/DevOps-Milestones/m1_demo_rails_project.git/).
- For source code management, we chose Git as version control system and pasted the ssh url (https://github.ncsu.edu/DevOps-Milestones/m1_demo_rails_project). After that we generated the public key and private key. Then we added the private key as Jenkins credential and added public key as repository deploy key. Then for credential dropdown in source code management, we chose the credencial just created. The default branch is master branch, we can specific any other existed branches.
- For build triggers, we chose
Build when a change is pushed to GitHubfor later webhook.
- For post-build actions, we enabled email notification. So after each build, we will receive an email about build informations.