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:
Client:
Version: 1.12.5
API version: 1.24
Go version: go1.6.4
Git commit: 7392c3b
Built: Fri Dec 16 06:14:34 2016
OS/Arch: windows/amd64
Server:
Version: 1.12.5
API version: 1.24
Go version: go1.6.4
Git commit: 7392c3b
Built: Fri Dec 16 06:14:34 2016
OS/Arch: linux/amd64
view raw output01.txt hosted with ❤ by GitHub

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.
C:\Users\Chairat\Git\demo-spring-boot-master>git init
Initialized empty Git repository in C:/Users/Chairat/Git/demo-spring-boot-master/.git/
view raw command01.txt hosted with ❤ by GitHub
Use command git add . to add files to Git staging area.
C:\Users\Chairat\Git\demo-spring-boot-master>git add .
view raw command02.txt hosted with ❤ by GitHub
Use command git commit -m "Initial Commit" to commit files to your Git repository.
C:\Users\Chairat\Git\demo-spring-boot-master>git commit -m "Initial Commit"
[master (root-commit) e39fd0a] Initial Commit
20 files changed, 654 insertions(+)
create mode 100644 .gitignore
create mode 100644 README.md
create mode 100644 model/pom.xml
create mode 100644 model/src/main/java/com/demo/DatabaseConfiguration.java
create mode 100644 model/src/main/java/com/demo/JDBCApplication.java
create mode 100644 model/src/main/java/com/demo/feature01/User.java
create mode 100644 model/src/main/java/com/demo/feature01/UserNotFoundException.java
create mode 100644 model/src/main/java/com/demo/feature01/UserRepository.java
create mode 100644 model/src/main/java/com/demo/feature01/UserRowMapper.java
create mode 100644 model/src/main/resources/application.properties
create mode 100644 model/src/main/resources/schema.sql
create mode 100644 model/src/test/java/com/demo/feature01/UserRepositoryTest.java
create mode 100644 model/src/test/resources/application.properties
create mode 100644 model/src/test/resources/schema.sql
create mode 100644 pom.xml
create mode 100644 rest/pom.xml
create mode 100644 rest/src/main/java/com/demo/Application.java
create mode 100644 rest/src/main/java/com/demo/JBossProxyInitializer.java
create mode 100644 rest/src/main/java/com/demo/feature01/FeatureController.java
create mode 100644 rest/src/test/java/com/demo/feature01/FeatureControllerTest.java
view raw output02.txt hosted with ❤ by GitHub


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>
C:\Users\Chairat\Git\demo-spring-boot-master>git remote add origin https://github.com/pacroy/demo-spring-boot.git
view raw command03.txt hosted with ❤ by GitHub

Then use command git push --set-upstream origin master to push files to your Git repository on GitHub.
C:\Users\Chairat\Git\demo-spring-boot-master>git push --set-upstream origin master
Counting objects: 45, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (45/45), 8.37 KiB | 0 bytes/s, done.
Total 45 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/pacroy/demo-spring-boot.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
view raw command04.txt hosted with ❤ by 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.
REPOSITORY TAG IMAGE ID CREATED SIZE
jenkins 1.651.3 d5c0410b1b44 6 months ago 736.9 MB
view raw output03.txt hosted with ❤ by GitHub

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:
INFO: Jenkins is fully up and running
view raw output04.txt hosted with ❤ by GitHub
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