Saturday, December 24, 2016

Test Drive Jenkins using Docker - Part I

This blog post is available on Medium. Click here to see this story on Medium.

Jenkins is now popular these days as a continuous integration and continuous delivery tool to automate software development process to achieve DevOps objectives. I have a chance to see a demo during the Test-Driven Development training last week at IMC Institue by K.Somkiat Puisungnoen (www.somkiat.cc)



Here I have listed instructions I tried on Windows 10 that you can follow if you are new to Jenkins and want to see what it can do. Thank you very much to Nont who spent an hour to help me setting Jenkins up.

PS: I'm not the expert but just tried this out for the first time so your comments and suggestions will be very appreciated.

Instructions Summary

  1. Part I: Install Docker
  2. Part I: Clone repository from GitHub
  3. Part I: Download and start up Jenkins 
  4. Part II: Add new project "PULLCODE" to connect to GitHub repository
  5. Part II: Add new project "BUILD" to build project with Maven
  6. Part II: Run MariaDB and test BUILD
  7. Part III: Install and create Build Pipeline
  8. Part III: Install JaCoCo to check for test coverage
  9. Part III: Install Build Monitor View and schedule run interval

1. Install Docker

  • To avoid touching your Windows system, we will use Docker as a container for this demo.
  • To learn about what Docker is. Click here.
  • To download Docker for Windows. Click here.
  • To learn how to install Docker on Windows. Click here.
  • To learn how to get started with Docker. Click here.

After you have installed Docker, you may test it by typing this into Windows command line: docker version and you should see something like this:

2. Clone repository from GitHub

In this demo we will use an existing Maven project created by K'Somkiat on GitHub by cloning his repository (or my repository) to your GitHub account. To learn more about Git, see this blog.

Download Git Client from here and install it.

Go to this this repository (or my repository) and click to download ZIP.
Note: If you don't want complication from installing MariaDB, you may use this repository instead.


Extract ZIP file to a folder and command prompt there (here is your working directory). Use command git init to create a new Git repository.
Use command git add . to add files to Git staging area.
Use command git commit -m "Initial Commit" to commit files to your Git repository.


Log in to your GitHub account (Sign up if you don't have an account) and create a new repository.



Give a name to your new repository and click Create.



Now you've got a blank repository. Please note your repository URL.



Go back to your command prompt and use command git remote add origin <your Git repository URL>

Then use command git push --set-upstream origin master to push files to your Git repository on GitHub.

Now, if you go back to your GitHub you should see files in your own repository like this:


3. Download and Start up Jenkins

Use command docker pull jenkins:1.651.3 to download Jenkins Docker image version 1.651.3 (You may use the newer or latest version but I'll use this version which I'm familiar with).

If you want to install locally without using Docker, you can download the war file here. You can find the older version by the link below.



Once your pull is done, use command docker images then you should see the image is now available on your local.

Start up a new Jenkins container by using command docker run -d --name jenkinsdemo -p 8080:8080 jenkins:1.651.3 

If you install Jenkins locally you can start it up by using command java -jar "jenkins v1.651.3.war"
Check your container's log by command docker logs jenkinsdemo and look for the line:
This tells your Jenkins is ready to use. 

Open Jenkins with web browser at http://localhost:8080/ and you should see the dashboard like this.



Continue in Part II...

6 comments:

  1. Updated section 2 to download and create new repository using git command lines instead of cloning repository.

    ReplyDelete
  2. Add link to my blog about Git (http://www.pacroy.com/2017/01/learn-git-within-7-minutes-and-play.html) in the section 2

    ReplyDelete
  3. Add alternative repository https://github.com/pacroy/demo-jenkins in section 2. This one does not require MariaDB.

    ReplyDelete
  4. Replaced console commands and outputs with Gist

    ReplyDelete