Continuous Integration - leortyz/softwareEngineeringResources GitHub Wiki

Objectives

  • Automatically run tests after uploading new code to an existing repository using Jenkins.
  • Obtain a report with the results of the tests.

Requirements

Introduction

Continuous integration is a software development practice where a new code is joined to an existing code that is hosted in a repository. The union of codes comes with automatic execution of tests to ensure its correct operation[1].
The goal of continuous integration is to quickly detect and locate bugs, so reduce the time to fix and improve the software, and that updates are available as soon as possible.
To carry out this workshop, you must use Jenkins as a continuous integration tool. Jenkins is Open Source and runs as a server on the host machine; In addition, it has numerous plugins that increase its capabilities.
Additionally, you must use Ngrok, which is a tool that allows exposing a local url to a public url.
For this workshop, Jenkins will run locally on your computer, by uploading the changes to our remote repository hosted on Github, it will be able to send a response to our server, so it is necessary to have a public url to expose our local server to the internet. Here Ngrok intervenes that will act as a communication bridge between Github and Jenkins.

Activities

Step 1: Install Requirements

Jenkins
  1. Go to the following https://jenkins.io/download/
  2. Download Jenkins (LTS o Weekly) for your OS.
  3. Follow the steps shown in the following tutorial: Windows [2] o ubuntu[3]

Ngrok

  1. Go to the following https://dashboard.ngrok.com/signup
  2. Create an account. Github is recommended
  3. Download the file

img 4. Unzip the file

//Replace <your authtoken> with the token given in the page
./ngrok authtoken <your authtoken>
  1. Open the program and enter the following command
    Note: The authtoken is in the 2nd item of the ngrok page.
  2. To test the operation, write the following command.

img

./ngrok http 8080
  1. Take note of the highlighted URL and do not close the console.
    Note: ngrok will give you a random URL every time the command is entered. Do not close.

Step 2: Create a Repository

  1. Create a Github repository
  2. Set up your Jenkins connection
  3. Go to Settings > Webhook > Add Webhook
  4. In Payload URL, place your url as follow:
<your url>/github-webhook/. 
For example: http://e760c763.ngrok.io/github-webhook/
  1. In Content type, select application/json
  2. Leave the rest of the options as they are and click on Add WebHook
  3. Check the console again and verify the connection

img

Step 3: Prepare Jenkins

  1. Select option β€œManage Jenkins” > Manage Plugins
  2. Select the Available tab and search β€œtest-results-analyzer”
  3. Mark the check Install y click β€œInstall without restart”

Step 4: Create a project in Jenkins

  1. Select the option β€œNew Item” in the left menu
  2. Enter a name, select β€œFreestyle Project” and click Ok
  3. In the tab β€œGeneral”, mark Github Project and write your repository url.

img

  1. In the tab β€œSource Code Management”, select git and enter the url again.

img

  1. In the tab β€œBuild Trigger”, select the option β€œGitHub hook trigger for GITScm polling”
  2. In the tab β€œBuild”
    a. Select β€œInvoke Gradle script”
    b. Enter data as follow

img

  1. In the tab β€œPost-build Actions”, enter data as follow.

img

  1. Click Save.

Step 5: Check communication between Github and Jenkins

  1. Clone this repository: ContinuousIntegration
  2. Open the project with Eclipse and verify the program and the test are running correctly.
  3. Place the content in the repository created at step 1
  4. Push to the repository
  5. Review Jenkins and check a new build is running (lower left corner). The first build always takes more time, wait to the end and get the results.
  6. When complete successfully, it will be marked in blue next to the build number. If it is marked in red, there are errors.

img

  1. From the side menu, select "Test Results Analyzer” to get charts about the tests performed and save those charts.

Development

After reviewing the code with the development team, a bug was found in one of the methods, although it does not show compilation errors and passes written tests, it is necessary to correct it to avoid further problems in the development process.

img

What you have to do:

  1. Correct the error in isLess method in the correct relational operator, it should be only <
  2. Upload changes to repository
  3. Review the report obtained in Jenkins (save the graphics)

After review again, the error was corrected, but the Jenkins report indicates that not all tests have been passed successfully.
In addition, it was identified that missing test cases that have not been included and are necessary.
You should:

  • Correct the necessary tests
  • Add additional tests. There should be 6 tests in total, 3 for each method.
  • Upload changes to repository
  • Review Jenkins report (save charts)

Deliverables

  1. Practice report with at least: cover, introduction, development, conclusions and recommendations, and references.
  2. Answer these questions in the report:
    a. What is continuous integration?
    b. Why is it important and almost necessary?
    c. In what type of projects is it recommended to apply it?
    d. What would be the result of not doing the continuous integration of a project?
    Note: Do not include the questions, these are only a guide.
  3. In the development of the report, include screens of the practice process. 6 graphs should be about the tests process (pie and bars for each build, the line graph is not necessary)
  4. Include in the report the url of the repository where you did the practice.

Rubric

╔════════════════════════════════════════════════════════════════════╦═══════╗
β•‘ Description                                                        β•‘ Value β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Testing code (in the repository)                                   β•‘   50  β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Practice report                                                    β•‘   50  β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Penalty per hour or fraction of delay                              β•‘  -30  β•‘
╠════════════════════════════════════════════════════════════════════╬═══════╣
β•‘ Penalty for not uploading required deliverables as specified       β•‘  -30  β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•

References

  • 01 Amazon, Β«What is Continuous Integration?,Β»
  • 02 P. Nguyen, Β«How to Install Jenkins on WindowsΒ»
  • 03 E. Evans, Β«Installing Jenkins on Ubuntu 16.04Β»
⚠️ **GitHub.com Fallback** ⚠️