Instructions Summary
- Part I: Install Docker
- Part I: Clone repository from GitHub
- Part I: Download and start up Jenkins
- Part II: Add new project "PULLCODE" to connect to GitHub repository
- Part II: Add new project "BUILD" to build project with Maven
- Part II: Run MariaDB and test BUILD
- Part III: Install and create Build Pipeline
- Part III: Install JaCoCo to check for test coverage
- Part III: Install Build Monitor View and schedule run interval
4. Add new project "PULLCODE"
Create new item.Name your project "PULLCODE" and select Freestyle project. Click OK to create.
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
Click Manage Jenkins
Click Manage Plugins
Go to tab Available and search for GitHub Plugin. Select it and Click Install without restart.
Wait until the all processes are completed.
Restart Jenkins by going to http://localhost:8080/restart and click Yes.
Wait until you get back to the first screen.
Go back to project PULLCODE's config.
In the section Source Code Management, select Git and input your repository URL. In the field Credential, click Add --> Jenkins.
Input Username and Password of your GitHub account and name your credential in the Description field as your reminder. Click Add.
Select Credential with the one you've just added and then click Save.
Test your project by clicking Build Now.
A new item appears in the Build History. Click on small triangle icon to expand the menu.
Select Console Output
You should see the build is finished successfully. Please note the PULLCODE's workspace location.
5. Add new project "BUILD"
Add another Freestyle project "BUILD".In the project config, click Advance... in the Advanced Project Options.
Choose Use custom workspace and input PULLCODE's workspace location. Click Save.
In JDK section, click Add JDK.
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)
Move down to Maven section, click Add Maven...
Select Install automatically and Name your Maven installation. Click Save.
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.
Select Marven Version with the one you've just created and input clean install in the Goals field. Click Save.
Build the project and wait until it finishes. Your build should end in failure.
If you go up and analyze your build log, you will see the failure because it could not connect to the database MariaDB.
6. 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.17 and 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.
- 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",
- Go to your working directory and edit the file application.properties in folder /model/src/test/resources/.
- Replace localhost with the Maria DB's IP Adrress from step 1 and Save
- Repeat the same steps with the same file name in folder /model/src/main/resources/.
- Use these commands to push your changes to your remote Git repository.
git add .
git commit -m "Updated MariaDB host"
git push - Rebuild the project PULLCODE
Now, you are ready to go. Rebuild the project BUILD and you should get a successful build.
Continue in Part III...
Updates section 6 to make changes on local repository and then push to remote repository instead of changing right on remote repository.
ReplyDeleteReplaced console outputs with Gist
ReplyDelete