Reader small image

You're reading from  Implementing DevOps with Microsoft Azure

Product typeBook
Published inApr 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781787127029
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Mitesh Soni
Mitesh Soni
author image
Mitesh Soni

Mitesh Soni has 8 years of experience in managing software for GNU/Linux and other UNIX-like operating systems in production environment. He started working as a professional with DevOps from 2013 and has worked on several live projects related to DevOps. https://www.linkedin.com/in/alessiogarofalo
Read more about Mitesh Soni

Right arrow

Chapter 3. Continuous Integration with VSTS

As we look ahead into the next century, leaders will be those who empower others.                                                                                                                                                                                                                                                                        --Bill Gates

In the previous chapter, we covered details on Visual Studio Team Services (VSTS). In this chapter, we will see how to utilize VSTS for continuous integration. We will use a sample Spring application available on GitHub and try to integrate it with VSTS.

We already saw in Chapter 2, Getting Started with Visual Studio Team Services (VSTS), how to use TFVC; in this chapter, we will also see how to create a project where code is managed in Git.

This chapter shows how to configure application code for automated compilation, unit test case execution, and notify important stakeholders on the status of...

Overview of continuous integration


Let's understand what continuous integration means in simple English. 

Continuous Integration (CI) is a fundamental or base DevOps practice to commit code to a shared repository such as Git or SVN based on the bug fixes or feature completion. This change is verified against automated build using tools such as Ant or Maven, static code analysis tools such as SonarQube, and unit test execution with tools such as JUnit for Java.

Understanding of the CI differs based on what you have in practice while implementing it, but the core remains the same. Essentially, it is an application development practice. Team members share the code in the shared code repository and that results in integration. In the DevOps culture, we focus on collaboration and communication a lot. At first glance, it seems in place, but in practice, it is very difficult to get that culture into the mindset of developers, testers, and the operations team. 

The obvious question here is, why are...

Creating a build definition for VSTS project


The objective of this section is to configure a code repository with VSTS in such a way that every time a developer checks in the code into the repository, it should automatically trigger the build script to execute and thus complete compilation, unit test execution, and SonarQube analysis (static code analysis), and notify different stakeholders based on the outcome of the CI process.

We should always remember that a process is always the same irrespective of the tools we use, be it open-source tools or commercial tools. We need build scripts; in case of a Java-based project, we need build.xml for Ant or pom.xml for Maven to execute the build. We need unit test cases written in JUnit or any other supported language. 

Before explaining the steps for CI, we need to understand and remind ourselves that the DevOps is a culture and combination of people, processes, and tools. It is not only about automation. It is also about mindset change, change in...

Configuration of continuous build integration in VSTS


Once the build definition is created, we will configure the Maven task to give the path to pom.xml so build definition can use pom.xml, to compile the source code and create a package file.

Select Maven pom.xml. In the Maven POM file, give the path to pom.xml for the existing project:

Click on the ... icon to browse through the folders available in the existing project and select the path to pom.xml:

Scroll down; in our case, select pom.xml and click on OK:

In the case of Maven, there are different goals such as compile, test, and package. We will give package here. If the default goal is available in pom.xml, then we don't need to explicitly mention it here. 

Keep the Test Results Files setting as it is:

Select Copy Files to: tasks and keep Source Folder and Target Folder as it is. In the Contents box, enter **/*.war. It will copy the WAR file available in the source directory of the project from any path and copy it to the staging directory...

Unit test execution for automated testing


In the PetClinic example, unit tests are written in JUnit. Unit test cases individually and independently verify specific methods of an application. In build definition Maven tasks, the test configuration was kept as default. 

After executing the build successfully, we can go to Explorer tab and click on the Tests links in the build execution logs to get more details on the test execution.

Verify the total number of tests, the passed and failed percentage, and the duration of test execution:

To get more details, click on the Test link on the top bar. Click on the Test runs

Verify the Completed status of the test run in the Recent test runs. Double click on the entry:

We will get the summary, run type, build version number, and outcome in the form of a chart showing passed and failed test results. In the following chart, it shows that all 41 unit tests have been executed successfully:

Click on the Test results tab to get results based on unit tests available...

Continuous feedback on build execution


Build execution is important, but the significant part of the whole process is to get continuous feedback of the build execution status. For example, to send a notification in case of build execution failure or success to specific stakeholders.

On the VSTS Project, click on the settings icon, and it will bring up the PetClinic Team page:

Click on the Notifications tab:

Click on +New. Verify the template for the Build notification. Click on Next:

Configure the fields as per your need and click on Finish:

There are multiple notification templates available for the build status notification:

Similarly, we can create an notification when the build fails:

Verify all the created alerts in Team subscriptions:

For a self-exercise, observe whether all the alerts are triggered properly in terms of a specific event occurrence such as build success or build failure.

In the next section, we will cover how the Git project can be managed in VSTS.

Managing the Git project in VSTS


In this section, we will cover how to manage the Git project in VSTS; however, the build definition and its execution is for self-exercise.

On the main page of VSTS account, go to the Projects section. Click on New Project.

In Create new project, give Project name, select Scrum or Agile as the Work item process. Select Git as Version control. Click on Create:

Wait till the project creation process completes in VSTS. Here is the screen for the newly created project:

Click on the Code tab on the top bar and verify the details available in the Files section. Git related details are available:

Verify the History tab as well. The repository is still empty as we haven't performed check-in:

We will try to check-in the PetClinic code from the local system to Git available in VSTS. Before that, click on Generate Git credentials so we can use it from our local system to check-in the code into the Git repository available here.

Enter User name (primary) and Password. Click...

Task catalog and marketplace


In Build & Release, we can use many tasks after selecting a template. In the PetClinic build, we have used the Maven template for the build execution. It has a predefined set of tasks that needs to be executed. Based on the need, we can add more tasks from the task logs in the build definition.

All tabs contain all the tasks available to perform specialized tasks for application life cycle management:

The Build tab in Task catalog contains tasks related to CI: 

  • .NET Core (PREVIEW): This builds, tests, and publishes using .NET core command line
  • Android Build (deprecated; use Gradle): This builds an Android app using Gradle and optionally starts the emulator for unit tests
  • Android Signing: This signs and aligns the Android APK files
  • Ant: This builds with Apache Ant
  • CMake: This builds with the CMake cross-platform build system
  • Gradle: This builds using a Gradle wrapper script
  • Grunt: This is the JavaScript Task Runner
  • Gulp: This is the Node.js streaming task-based build...

Summary


It is always better to fail at an early stage and recover sooner. In the case of application life cycle management, if we find issues at early stages, then we get more time to fix them, while severity and dependencies are less complex and can be easily sorted out. 

Continuous effort – not strength or intelligence – is the key to unlocking our potential.                                                                                                           —Winston Churchill

In this chapter, we covered CI for a Java-based web application.

After configuring and executing CI for the PetClinic project, where code is shared via TFVC repository, the next step should be to create a deployment environment. The deployment environment can be a development, QA, staging, or production environment.

In the next chapter, we will create Microsoft Azure Web Apps (Azure App Service), configure Azure web app with programming language specific settings (in our case configuration related to Java application...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Implementing DevOps with Microsoft Azure
Published in: Apr 2017Publisher: PacktISBN-13: 9781787127029
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime

Author (1)

author image
Mitesh Soni

Mitesh Soni has 8 years of experience in managing software for GNU/Linux and other UNIX-like operating systems in production environment. He started working as a professional with DevOps from 2013 and has worked on several live projects related to DevOps. https://www.linkedin.com/in/alessiogarofalo
Read more about Mitesh Soni