[DOCKER] CI / CD practice for beginners --Part3 --Preparation for development project

Build a CI / CD environment

This series is for super beginners who want to practice CI / CD. We hope that you will get a sense of "What is CI / CD?" When introducing the enterprise level and production level. The tools to be used are selected here, so if you want to use another tool, please check accordingly. The general content is as follows.

  1. Environment construction
  1. Build CI / CD tools
  2. ** Preparation for development project <-I will explain here ** --Register project data on GitHub --Installing Jenkins Plugin --Manual build
  3. Example of using CI / CD tool and other tools together
  4. Cooperation with test tools
  5. Cooperation with inspection tools
  6. Realization of pipeline

Overview </ font>

- GitHub remote and local repository settings --Automatic installation of Jenkins Plugin --Create, execute, and check results of jobs

Register project data on GitHub

To understand the usage examples of CI / CD tools, [Introduction to Jenkins Practice](https://www.amazon.co.jp/%E6%94%B9%E8%A8%82%E7%AC%AC3%E7 % 89% 88-Jenkins% E5% AE% 9F% E8% B7% B5% E5% 85% A5% E9% 96% 80-% E2% 80% 95% E2% 80% 95% E3% 83% 93% E3% 83% AB% E3% 83% 89% E3% 83% BB% E3% 83% 86% E3% 82% B9% E3% 83% 88% E3% 83% BB% E3% 83% 87% E3% 83% 97% E3% 83% AD% E3% 82% A4% E3% 82% 92% E8% 87% AA% E5% 8B% 95% E5% 8C% 96% E3% 81% 99% E3% 82% We will use the model project of 8B% E6% 8A% 80% E8% A1% 93-PRESS-plus / dp / 4774189286).

First, register the project data (Create a GitHub account and log in in advance) As shown in the figure below, click the `` `Fork``` button on the upper right at the link destination 図10.png

Then, `` ` / Jenkins_Practical_Guide_3rd_Edition``` will appear in your repository. 図11.png

Then get the project data in the local repository

Click <GitHub account> / Jenkins_Practical_Guide_3rd_Edition on the remote registry and then copy the link pointing to the branch on the remote registry

図12.png

Execute the following command on terminal

$ pwd
$ mkdir <demo directory>   //Create directory for demo development as appropriate
$ cd <demo directory>
$ git clone https://github.com/tem-individual/Jenkins_Practical_Guide_3rd_Edition.git sampleproject

Success if:

$ cd sampleproject
$ ls -a
.  ..  .git  Jenkinsfile  LICENSE  build.gradle  config  pom.xml  readme.md  src
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = https://github.com/<GitHub account>/Jenkins_Practical_Guide_3rd_Edition.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

Install Plugin

In this demo development, install the following 4 plugins

  • JaCoCo Plugin
  • Checkstyle Plugin
  • FindBugs Plugin
  • StepCounter Plugin

There are two ways to install the Jenkins Plugin

-Install via update site --Download and install by yourself

Note

When performing "Download and install by yourself", it is necessary to check the dependency of the Jenkins Plugin to be installed. In "Install via update site", other Plugins that depend on it will be installed automatically, so basically select the former.

Since the environment allows internet access, the former is used. Click here for the procedure

  1. Jenkins dashboard
  2. `Jenkins Management` in the left pane
  3. `Plugin Management` `in the center pane
  4. `Available` tab selection
  5. Enter `` `JaCoCo``` in the search window and install as follows

図13.png

After returning to the top page, install other plugins as well

Performing a manual build

Let's actually use Jenkins Various operations other than manual build will be introduced from the next time onwards.

** The implementation flow is as follows **

  1. Job settings
  2. Create a new job
  3. VCS settings
  4. Build trigger settings
  5. Build task settings
  6. Post-build processing settings
  7. Run the build
  8. Save the release target

** Job settings ** "Create a new job" dashboard> Create a new job` `> Name the Item "Jenkins JOB", select `` `FreeStyle project and click OK

"VCS settings" Input as shown in the figure below Also, if your GitHub project is `privacy```, you will need to enter the Credential (This time, we are forking the `publish``` project, so no input is required.)

図14.png

"Build Trigger Settings" Not set this time because it is a manual build

"Build task settings" Enter as shown in the figure below and click "Save"

Figure 15.png

"Post-build processing settings" Not set this time because it is a manual build

** Run build ** Select `` `Build Now``` as shown below to execute the build. 図18.png If the build result is successful, it will be ● </ font> * 1 as surrounded by the red frame.

※1 ● </ font>: No problem ● </ font>: Build successful. There is a problem with test results and code analysis ● </ font>: Build failure ● </ font>: Build not executed

When checking build history or specific build information

  1. dashboard
  2. ``` Build history``in the left pane --You can check the list of build history
  3. Click on a specific build --From Workspace, you can check the contents of the project in the directory structure. --Only the latest changes can be confirmed from `` `Recent Change``` --In addition, you can check who executed it, test results, etc.

** Saving the release target ** Finally, set the release target to be placed in a place where you can easily check it.

Select a specific job such as "Jenkins JOB"> `Settings` `>` `Post-build processing` Select `Save artifacts` and specify the path

図20.png

Running the build will create a `` `sampleproject.war``` on the dashboard or host

図21.png

$ sudo su -
$ cd /var/lib/docker/volumes/jenkins-data/_data/workspace/JenkinsJOB/target
$ ls
checkstyle-cachefile    checkstyle-result.xml  findbugsXml.xml    generated-test-sources  maven-archiver  sampleproject-1.0.0  surefire-reports
checkstyle-checker.xml  classes                generated-sources  jacoco.exec             maven-status    sampleproject.war    test-classes

Recommended Posts