{"id":5708,"date":"2016-03-17T11:42:54","date_gmt":"2016-03-17T02:42:54","guid":{"rendered":"https:\/\/appkitbox.com\/en\/?page_id=5708"},"modified":"2016-03-17T11:42:54","modified_gmt":"2016-03-17T02:42:54","slug":"jenkins-beginner-my-first-continuous-integration","status":"publish","type":"page","link":"https:\/\/appkitbox.com\/en\/knowledge\/jenkins-beginner-my-first-continuous-integration\/","title":{"rendered":"Jenkins Beginner: My First Continuous Integration"},"content":{"rendered":"<style>\nmain .wrappedtopicnormal {margin-bottom:30px;}\nmain p+h5 {margin-top:30px;}\nmain p+h6 {margin-top:30px;}\n.pre {white-space:pre;}\n.pre br {display:none;}\n<\/style>\n<p style=\"text-align:right;\">Hiroki Maruchi and Shoichi Iwai, GBA Co., Ltd.<\/p>\n<p class=\"listtitle\">Table of Contents<\/p>\n<ol style=\"margin-bottom:50px;\">\n<li><a href=\"#t1\">Introduction<\/a><\/li>\n<li><a href=\"#t2\">INSTALLING JENKINS<\/a><\/li>\n<li><a href=\"#t3\">USING JENKINS<\/a>\n<ul style=\"margin-top:20px;\">\n<li><a href=\"#t3-1\">Creating a Job: Create Hello World<\/a><\/li>\n<li><a href=\"#t3-2\">Creating a Job: Build an Android Studio Project<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#t4\">CONNECTING JENKINS AND THE EMULATOR: CREATE AN AUTOMATIC TEST<\/a>\n<ul style=\"margin-top:20px;\">\n<li><a href=\"#t4-1\">Connecting to an Emulator<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#t5\">CONCLUSION<\/a><\/li>\n<\/ol>\n<h3 id=\"t1\">1. Introduction<\/h3>\n<p>Jenkins is an open source, continuous integration (CI) tool.<\/p>\n<p>Jenkins integrates with version control tools (Git and CVS are examples of such tools) and integrates with the build for programming languages, such as Java, for which compilation is necessary, shell script, and batch commands. With the use of Jenkins, you can build a project platform that groups development projects. Moreover, by continuously using Jenkins in projects, it can provide an integrated infrastructure that improves communication between development team members and the work process.<\/p>\n<p>This article provides a demonstration of Jenkins using simple examples. Additionally, subsequent articles integrate with RTK and create a platform to automatically test actual smartphones.<\/p>\n<h3 id=\"t2\">2. Installing Jenkins<\/h3>\n<p class=\"listtitle\">Installing Jenkins<br \/>\nHere, we show an example of installing Jenkins with Homebrew.<br \/>\nRun Terminal and input the following command:<\/p>\n<div class=\"wrappedtopicnormal\" style=\"overflow-x:auto;\">\n<p class=\"pre\">hiroki-no-MacBook-Air:~ hiroki$ brew install jenkins<br \/>\n==&gt; Downloading http:\/\/mirrors.jenkins-ci.org\/war\/1.602\/jenkins.war<br \/>\n                                                                           0.3%<br \/>\n######################################################################## 100.0%<br \/>\n==&gt; jar xvf jenkins.war<br \/>\n==&gt; Caveats<br \/>\nNote: When using launchctl the port will be 8080.<\/p>\n<p class=\"pre\">To have launchd start jenkins at login:<br \/>\n    mkdir -p ~\/Library\/LaunchAgents<br \/>\n    ln -sfv \/usr\/local\/opt\/jenkins\/*.plist ~\/Library\/LaunchAgents<br \/>\nThen to load jenkins now:<br \/>\n    launchctl load ~\/Library\/LaunchAgents\/homebrew.mxcl.jenkins.plist<br \/>\nOr, if you don't want\/need launchctl, you can just run:<br \/>\n    jenkins<br \/>\n==&gt; Summary<br \/>\n  \/usr\/local\/Cellar\/jenkins\/1.602: 6 files,  66M, built in 99.7 minutes<br \/>\nhiroki-no-MacBook-Air:~ hiroki$<\/p>\n<\/div>\n<h5>Running Jenkins<\/h5>\n<p>Next, we will use Terminal to run Jenkins from a shell.<br \/>\nInput the following command:<\/p>\n<div class=\"wrappedtopicnormal\" style=\"overflow-x:auto;\">\n<p class=\"pre\">$ java -jar \/usr\/local\/Cellar\/Jenkins\/1.602\/libexec\/Jenkins.war<\/p>\n<\/div>\n<h5>Confirming That Jenkins is Running<\/h5>\n<p>Let's access the running Jenkins and display it.<br \/>\nStart your Web browser, input <span class=\"redletter\">http:\/\/localhost:8080<\/span> into the address bar, and press the ENTER key. The Jenkins screen will appear as follows:<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/001-3.png\" alt=\"001\" width=\"802\" height=\"755\" class=\"alignleft size-full wp-image-5710\" \/><\/div>\n<h3 id=\"t3\">3. Using Jenkins<\/h3>\n<h4 id=\"t3-1\">Creating a Job: Create Hello World<\/h4>\n<h5>Creating a new job<\/h5>\n<p>Click <span class=\"redletter\">New Item<\/span>. The Job Basic Settings screen appears. Here, we will input the following items.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/0011-3.png\" alt=\"001\" width=\"802\" height=\"755\" class=\"alignleft size-full wp-image-5711\" \/><\/div>\n<h5>Settings:<\/h5>\n<table>\n<thead>\n<tr>\n<th>Settings name<\/th>\n<th>Value<\/th>\n<th>Notes<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Item name<\/td>\n<td>Test<\/td>\n<td>Any desired name<\/td>\n<\/tr>\n<tr>\n<td>Check box<\/td>\n<td>Freestyle project<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Click <span class=\"redletter\">OK<\/span> to move to the next screen.<\/p>\n<h5>Advanced settings<\/h5>\n<p>The Advanced Settings screen appears. Here, we will input the following items.<\/p>\n<h5>Build settings<\/h5>\n<p>From the drop-down menu, select <span class=\"redletter\">Execute shell<\/span>.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/002-3.png\" alt=\"002\" width=\"802\" height=\"838\" class=\"alignleft size-full wp-image-5713\" \/><\/div>\n<p>The <span class=\"redletter\">Command<\/span> field will be added and then displayed. Here, we will input the following into the <span class=\"redletter\">Command<\/span> field:<\/p>\n<p>echo 'hello world.'<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/003-3.png\" alt=\"003\" width=\"802\" height=\"838\" class=\"alignleft size-full wp-image-5714\" \/><\/div>\n<h5>Running a job<\/h5>\n<p>Display the Jenkins top page. If a job has been registered, a screen similar to the following appears.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/004-3.png\" alt=\"004\" width=\"808\" height=\"601\" class=\"alignleft size-full wp-image-5715\" \/><\/div>\n<p>Select the job that you want to run.<\/p>\n<h5>Running a job<\/h5>\n<p>The top page of the job that you created appears.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/005-3.png\" alt=\"005\" width=\"808\" height=\"601\" class=\"alignleft size-full wp-image-5716\" \/><\/div>\n<p>Here, select <span class=\"redletter\">Build Now.<\/span><br \/>\nAfter a short while, the run result is added to the <span class=\"redletter\">Build History<\/span> field.<\/p>\n<h5>Displaying the run job result<\/h5>\n<p>Click the job that you want to display from the <span class=\"redletter\">Build History<\/span> field. A page showing the detailed results of the run job appears.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/006-3.png\" alt=\"006\" width=\"808\" height=\"601\" class=\"alignleft size-full wp-image-5718\" \/><\/div>\n<p>Now click <span class=\"redletter\">Console Output<\/span>. The run result of the registered shell script appears.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/007-3.png\" alt=\"007\" width=\"808\" height=\"601\" class=\"alignleft size-full wp-image-5719\" \/><\/div>\n<h5>Conclusion<\/h5>\n<p>In this chapter, we used Jenkins for the first time and created a very simple job of only displaying a message.<\/p>\n<p>In this example, notice that we ran a shell command of a development PC that runs Jenkins. Like in this example, in Jenkins you can register and group various operations necessary for software development, such as commands, into a job. You can group necessary operations into a job and register it as one meaning in Jenkins. This means that they can be run with one GUI button. Jenkins runs the provided operations and records the result.<br \/>\nThe level of abstraction for commands issued with the CUI are comparatively high and a certain amount of development skill is required. In contrast, with Jenkins anyone can run even complicated and difficult operations with the click of a button by grouping them like this by meaning. Moreover, as Jenkins can be accessed with a Web browser, it can be shared with and accessed by members of a team such as a development group. Next, let's register useful functions in a Jenkins job so that development operations and testing can be performed easily.<\/p>\n<h4 id=\"t3-2\">Creating a Job: Build an Android Studio Project<\/h4>\n<p>In the previous procedure, we displayed a simple message. This time, we will operate Android project, which is created by using Android Studio, on Jenkins.<br \/>\nGenerally speaking, apps for Android are developed in Java. In Java, the source must be compiled to run the app on an actual device. In the previous article, the developer's <span class=\"redletter\">Run<\/span> button was clicked to run this compile. In the same manner as this procedure, we will run it on Jenkins.<\/p>\n<h5>Creating a new job<\/h5>\n<p>Create a new job.<br \/>\nInput a job name and select <span class=\"redletter\">Freestyle project<\/span>.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/0012-3.png\" alt=\"001\" width=\"961\" height=\"630\" class=\"alignleft size-full wp-image-5720\" \/><\/div>\n<h5>Specifying the source code location<\/h5>\n<div class=\"wrappedtopicnormal\" style=\"overflow-x:auto;\">\n<p class=\"pre\">Advanced project option<br \/>\n  &gt; Use a custom workspace<br \/>\n    &gt; Directory field: \/Users\/hiroki\/AndroidStudioProjects\/calculator<\/p>\n<p class=\"pre\">Build<br \/>\n  &gt; Run the shell<br \/>\n    &gt; Command field: .\/gradlew build # Run the build<\/p>\n<p class=\"pre\">Post-build Actions<br \/>\n  &gt; Save the result<br \/>\n    &gt; Field for the file to be saved: **\/*.apk<\/p>\n<\/div>\n<p>Once setup is complete, click the <span class=\"redletter\">Save<\/span> button to save the job.<\/p>\n<h5>Running a job<\/h5>\n<p>Click <span class=\"redletter\">Build Now<\/span>. The job runs.<\/p>\n<h5>Displaying the result<\/h5>\n<p>When a job is run and then completes, the result of whether the job ran successfully or failed is succinctly displayed using the icons of green and red traffic lights. At the end of this job, the .apk file is displayed on the project main page as \"result of the latest successful build.\" You can download this file directly.<\/p>\n<h3 id=\"t4\">4. Connecting Jenkins and the Emulator: Create an Automatic Test<\/h3>\n<p>In the previous chapter, we used Jenkins to automate everything up to the build. This time we are going to try to install the app we built on the emulator and check whether it is installed successfully. We will also rent an actual device in the cloud with RTK and in the same way install the app and check whether it was installed on the device.<\/p>\n<h4 id=\"t4-1\">Connecting to an Emulator<\/h4>\n<p>Install the .apk file built in Jenkins on an Android emulator.<\/p>\n<p>Firstly, start the virtual Android terminal (Android emulator) configured on the development PC, and then install the app file on the emulator.<\/p>\n<h5>Preparation<\/h5>\n<h6>Starting the emulator<\/h6>\n<p>Start the Android emulator on the development PC and make this accessible from Jenkins. Firstly, start the Android emulator. Input the following command:<\/p>\n<div class=\"wrappedtopicnormal\" style=\"overflow-x:auto;\">\n<p class=\"pre\">hiroki-no-MacBook-Air:calculator<br \/>\nhiroki$ \/Users\/hiroki\/Library\/Android\/sdk\/tools\/emulator -netdelay none -netspeed full -avd Nexus_5_API_21_x86&<\/p>\n<\/div>\n<p>Once you input the command, the virtual terminal screen will appear.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/0013-3.png\" alt=\"001\" width=\"360\" height=\"598\" class=\"alignleft size-full wp-image-5759\" \/><\/div>\n<p>Keep the emulator running so that it can be accessed from Jenkins at any time.<\/p>\n<h5>Creating a Job: Install the App on the Emulator<\/h5>\n<h6>Setting up a job<\/h6>\n<p>Modify the project we created in the previous procedure. Specifically, only the following procedure is added.<\/p>\n<ul>\n<li>Check the connection to the Emulator<\/li>\n<li>Install the .apk file on the Android emulator<\/li>\n<\/ul>\n<div class=\"wrappedtopicnormal\" style=\"overflow-x:auto;\">\n<p class=\"pre\">Advanced project option<br \/>\n  &gt; Use a custom workspace<br \/>\n    &gt; Directory field: \/Users\/hiroki\/AndroidStudioProjects\/calculator<\/p>\n<p class=\"pre\">Build<br \/>\n  &gt; Run the shell<br \/>\n    &gt; Command field: .\/gradlew build # Run the build<br \/>\n  &gt; Run the shell<br \/>\n    &gt; Command field: .\/gradlew connectedAndroidTest # Test the connection to the terminal<br \/>\n  &gt; Run the shell<br \/>\n    &gt; Command field: .\/gradlew installDebug # Install .apk for debugging on terminal<\/p>\n<p class=\"pre\">Post-build Actions<br \/>\n  &gt; Save the result<br \/>\n    &gt; Field for the file to be saved: **\/*.apk<\/p>\n<\/div>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/0021-3.png\" alt=\"002\" width=\"894\" height=\"976\" class=\"alignleft size-full wp-image-5721\" \/><\/div>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/0031-3.png\" alt=\"003\" width=\"1007\" height=\"974\" class=\"alignleft size-full wp-image-5722\" \/><\/div>\n<p>Once setup is complete, click the <span class=\"redletter\">Save<\/span> button to save the job.<\/p>\n<h6>Starting a job<\/h6>\n<p>Start a job in the same way as the previous procedure. Once the job runs, check the connection with the emulator, and install the built .apk file on the Android emulator.<\/p>\n<h6>Displaying the result<\/h6>\n<p>Once the test completes, a screen similar to the following appears.<\/p>\n<div class=\"l-imgbox\"><img loading=\"lazy\" src=\"https:\/\/appkitbox.com\/en\/wp-content\/uploads\/sites\/2\/0041-3.png\" alt=\"004\" width=\"1003\" height=\"860\" class=\"alignleft size-full wp-image-5723\" \/><\/div>\n<p>If a test is successful like this example, a green light is displayed to indicate that it was successful.<br \/>\nIf you click the row with the latest time in the build history, the details of the result will be displayed. If you click <span class=\"redletter\">Console Output<\/span>, the recorded console rows will all be displayed.<br \/>\nThe details of the results for the project built from the source, connection test, and installation of the .apk package on the emulator running on the development PC will be displayed. In this example, at the end of every row \"BUILD SUCCESSFUL\" is displayed (none are displayed as \"Error\").<\/p>\n<h3 id=\"t5\">5. Conclusion<\/h3>\n<p>In this article, we used Jenkins to register operations like a build that used a shell command in a job, and ran the job.<br \/>\nNormally, when developing an Android app, considerably difficult and complicated operations, such as the Java build and compile, must be performed internally. Therefore, a lot of the times those operations can only be understood and run by the person in charge, and that tends to become a \"personnel\" bottleneck when looked from the overall development process.<\/p>\n<p>In Jenkins, by registering these operations in jobs, an operation interface for run links and the like is provided, and just the success\/fail result can be indicated. Complicated operations can be hidden, processes can be converted to symbols and modules, and used publicly. Through this, an objective and clear overall development process can be created.<\/p>\n<p>By using the continuous integration tool Jenkins, app developers, programmers, designers, testers, and any stockholders related to development can share builds and tests. Each process can be \"visualized,\" meaning that a platform can be put into place in which any inefficiency can be improved and software can be created by all parties.<\/p>\n<p>In the next article, we will use the RTK feature called RTK Thrift API to control an actual rental smartphone from the software.<\/p>\n<p>In the article after that, we will sum everything up and build a platform to carry out continuous development activities with project members who continually test actual smartphones from Jenkins.<\/p>\n<p style=\"margin-top:30px;\">Glossary<\/p>\n<p>Homebrew<\/p>\n<p>Package management software for Mac OS X<\/p>\n<p style=\"margin-top:30px;\">References<\/p>\n<p>K. Sato, T. Wada, M. Kawamura, et al. (2015) Jenkins jissen nyumon (Practical Introduction to Jenkins), Gijutsu-Hyohron Co., Ltd.<\/p>\n<p>M. Fewster and D. Graham (1999) Software Test Automation, Addison-Wesley<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hiroki Maruchi and Shoichi Iwai, GBA Co., Ltd. Table of Contents Introduction INSTALLING JENKINS USING JENKINS Creating a Job: Create Hello World Creating a Job: Build an Android Studio Project CONNECTING JENKINS AND THE EMULATOR: CREATE AN AUTOMATIC TEST Connecting to an Emulator CONCLUSION 1. Introduction Jenkins is an open source, continuous integration (CI) tool. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":5622,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"general-template.php","meta":{"content-type":""},"categories":[14],"aioseo_notices":[],"acf":[],"_links":{"self":[{"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/pages\/5708"}],"collection":[{"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/comments?post=5708"}],"version-history":[{"count":0,"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/pages\/5708\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/pages\/5622"}],"wp:attachment":[{"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/media?parent=5708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appkitbox.com\/en\/wp-json\/wp\/v2\/categories?post=5708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}