Setup a Jenkins installation running Docker in a VM through Vagrant to demonstrate a Jenkins-GitHub Continuous Integration. A NodeJS app is also provided for testing and will also be run on Docker.
- Make sure your machine supports Virtualization
- VirtualBox installed - get it from https://www.virtualbox.org/wiki/Downloads
- Vagrant installed - get it from http://www.vagrantup.com/downloads.html
- SSH client - you can use git-scm's built-in ssh client for Windows
- Fork this repo
- Clone your forked repo into your machine
- cd into the repo and run vagrant up
- Once the machine is up, ssh into your VM by running
vagrant ssh
- Run
docker logs jenkins
and look for something like the one below:
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
ea7358a1dfb44ab38531bba53ca608b7
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
Take note of the password as you will use that later
- Open your browser and access http://localhost:8080
- In Unlock Jenkins page, enter the password mentioned above
- In Customize Jenkins page, click Install suggested plugins
- Create your preferred Jenkins user
- Create a Jenkins job and use
Freestyle project
- On the configuration page, do the following:
- Under
General
, checkGitHub project
and enter your repo's web URL on Project url - Under
Source Management
, checkGit
and under Repository URL enter the same URL as above - Under
Build Triggers
, checkGitHub hook trigger for GITScm polling
orBuild when a change is pushed to GitHub
- Under
Build
, clickAdd build step
and selectExecute shell
- Under Command, enter the ff:
chmod +x deploy.sh ./deploy.sh
- Under Command, enter the ff:
- Click Save
- Under
- On your GitHub repo do the following:
- Click
Settings
- On the left, click
Integration Services
- Under
Services
, clickAdd service
and selectJenkins (GitHub plugin)
- Under
Jenkins hook url
, enter your Jenkins url likehttp://x.x.x.x:8080/github-webook/
- Where x.x.x.x is your public IP.
- Make sure your Jenkins installation is visible from the internet
- You can do this by forwarding port 8080 on your router to your machine
- Click
Add service
- Click
- Make a change on the
app.js
(e.g. change 'hello world' to 'hi world') save, commit and push - You should see your job automatically being built after the push and will fail because the test part expects a 'hello world' string
#app/test/test.js var request = require('supertest'); var app = require('../app.js'); describe('GET /', function() { it('respond with hello world', function(done) { request(app).get('/').expect('hello world', done); }); });
- Update
app.js
again to the correct one, save, commit and push and you should see your job being built and exit sucessfully - If your build finish successfully, the docker container running the app should be running and will be accessible at http://localhost:8000
MIT