Test Drive Jenkins using Docker — Part II

Image for post
Image for post

…Continued from Part I

Instructions Summary

Part I

  1. Install Docker
  2. Clone repository from GitHub
  3. Download and start up Jenkins

Part II

  1. Add new project “PULLCODE” to connect to GitHub repository
  2. Add new project “BUILD” to build project with Maven
  3. Run MariaDB and test BUILD

Part III

  1. Part III: Install and create Build Pipeline
  2. Part III: Install JaCoCo to check for test coverage
  3. Part III: Install Build Monitor View and schedule run interval

1. Add new project “PULLCODE”

Create new item.

Image for post
Image for post

Name your project “PULLCODE” and select Freestyle project. Click OK to create.

Image for post
Image for post

Now, we will connect this project to our GitHub repository. But before you can do that you need to install the Git plugin first. Click Back to Dashboard

Image for post
Image for post

Click Manage Jenkins

Image for post
Image for post

Click Manage Plugins

Image for post
Image for post

Go to tab Available and search for GitHub Plugin. Select it and Click Install without restart.

Image for post
Image for post

Wait until the all processes are completed.

Image for post
Image for post

Restart Jenkins by going to http://localhost:8080/restart and click Yes.

Image for post
Image for post

Wait until you get back to the first screen. Go back to project PULLCODE’s config.

Image for post
Image for post

In the section Source Code Management, select Git and input your repository URL. In the field Credential, click Add Jenkins.

Image for post
Image for post

Input Username and Password of your GitHub account and name your credential in the Description field as your reminder. Click Add.

Image for post
Image for post

Select credential with the one you’ve just added and then click Save.

Image for post
Image for post

Test your project by clicking Build Now.

Image for post
Image for post

A new item appears in the Build History. Click on small triangle icon to expand the menu.

Image for post
Image for post

Select Console Output

Image for post
Image for post

You should see the build is finished successfully. Please note the PULLCODE’s workspace location.

Image for post
Image for post

2. Add new project “BUILD”

Add another Freestyle project “BUILD”.

In the project config, click Advance… in the Advanced Project Options.

Image for post
Image for post

Choose Use custom workspace and input PULLCODE’s workspace location. Click Save.

Image for post
Image for post

Go to Manage JenkinsConfigure System.

Image for post
Image for post

In JDK section, click Add JDK.

Image for post
Image for post

Uncheck Install automatically, name your JDK installation, and input /usr/lib/jvm/java-8-openjdk-amd64 in JAVA_HOME field. (In case you don’t use Docker, put your local JDK directory here e.g. C:\Program Files\Java\jdk1.8.0_111

Image for post
Image for post

Move down to Maven section, click Add Maven…

Image for post
Image for post

Select Install automatically and Name your Maven installation. Click Save.

Image for post
Image for post

Go back to the project BUILD’s config and go down to the Build section, click Add build step and select Invoke top-level Maven targets.

Image for post
Image for post

Select Marven Version with the one you’ve just created and input clean install in the Goals field. Click Save.

Image for post
Image for post

Build the project and wait until it finishes. Your build should end in failure.

Image for post
Image for post

If you go up and analyze your build log, you will see the failure because it could not connect to the database MariaDB.

Image for post
Image for post

3. Install MariaDB and test BUILD

Note: If you use this alternative repository, you don’t need MariaDB.
In your windows command line, put docker run -d — name mariadb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=for_test mariadb:10.1.17and press enter. This will pull MariaDB version 10.1.17 and run it automatically.

Use command docker ps to display all containers. You should see 2 containers are running now including the mariadb.

Check if the database is created properly by using command docker exec -it mariadb mysql -u root -p”123456" and then followed by show databases;and you will see something like this:

PS: If you want to install MariaDB locally, you can download it from here. Then you may have to manually create the database named for_test.

If you use Docker, you need to perform the following steps to point JDBC connection to the Maria DB container you’ve created.

  1. Check Maria DB container you’ve just created by using command docker inspect mariadb and note the IP address in the line like: “IPAddress”: “172.17.0.3”
  2. Go to your working directory and edit the file application.properties in folder /model/src/test/resources/.
  3. Replace localhost with the Maria DB’s IP Adrress from step 1 and Save
  4. Repeat the same steps with the same file name in folder /model/src/main/resources/.
  5. Use these commands to push your changes to your remote Git repository.
    git add .
    git commit -m "Updated MariaDB host"
    git push
  6. Rebuild the project PULLCODE

Now, you are ready to go. Rebuild the project BUILD and you should get a successful build.

Image for post
Image for post

Continue in Part III…

Originally published at pacroy.blogspot.com on December 25, 2016.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store