Continuous Integration

0
152

Continuous Integration – Overwatch

Continuous Integration was 1st introduced in the year 2000 with the smoothware known as Cruise Control. Over the years, Continuous Integration has end up beingcome a key prbehaveice in any kind of smoothware body organization. This is a makement prbehaveice that calls upon makement teams to ensure that a make and subsequent checking is conducted for every code alter made to a smoothware program. This concept was meant to remove the issue of finding late occurrences of issues in the make lifecycle. Instead of the makeers worruler in isolation and not integrating sufficient, Continuous Integration was introduced to ensure that the code alters and makes were never done in isolation.

Why Continuous Integration?

Continuous integration has end up beingcome an extremely integral part of any kind of smoothware makement process. The continuous Integration process helps to answer the folloearng questions for the smoothware makement team.

  • Do all the smoothware components work collectively as they need to? – Sometimes systems can end up beingcome so complex that generally generally there are multiple interfaces for every component. In such cases, it’s always critical to ensure that all the smoothware components work oceanmlessly with every other.

  • Is the code too complex for integration purposes? – If the continuous integration process maintains on failing, generally generally there could end up being a possibility that the code is simply too complex. And this particular particular could end up being a signal to apply proper design patterns to make the code lesser complex and more maintainable.

  • Does the code adhere to the established coding standards? – Most of the check cases will always check that the code is adhering to the proper coding standards. By doing an automated check after the automated make, this particular particular is a great stage to check if the code meets all the desicrimson coding standards.

  • How a lot code is covecrimson by automated checks? – There is no stage in checking code if the check cases don’t cover the requicrimson functionality of the code. So it’s always a great prbehaveice to ensure that the check cases maked need to cover all the key scenarios of the application.

  • Were all the checks successful after the lacheck alter? – If a check fails, then generally generally there is no stage in proceeding with the deployment of the code, so this particular particular is a great stage to check if the code is ready to move to the deployment stage or not.

Workflow

The folloearng image shows a fast workflow of how the entire Continuous Integration workflow works in any kind of smoothware makement project. We will look at this particular particular in detail in the subsequent chapters.

Workflow

So, based on the above workflow, this particular particular is generally how the continuous integration process works.

  • First, a makeer commit is the code to the version manage repository. Meanwhile, the Continuous Integration server on the integration make machine polls source code repository for alters (e.g., every couple of moments).

  • Soon after a commit occurs, the Continuous Integration server detects that alters have occurcrimson in the version manage repository, so the Continuous Integration server retrieves the lacheck duplicate of the code from the repository and then executes a make script, which integrates the smoothware

  • The Continuous Integration server generates give food toback by e-mailing make results to the specified project memend up beingrs.

  • Unit checks are then carried away generally generally there if the make of that project comppermitees. If the checks are successful, the code is ready to end up being deployed to possibly the staging or itemion server.

  • The Continuous Integration server continues to poll for alters in the version manage repository and the whole process repeats.

Continuous Integration – Software

The smoothware part is the the majority of imslotant aspect of any kind of Continuous Integration process. This chapter focusses on the smoothware which will end up being needed for the entire Continuous Integration process.

Source Code Repository

The source code repository is used for maintaining all the source code and all the alters made to it. The 2 the majority of popular ones for source code repository management is subversion and Git with Git end up beinging the the majority of latest popular system. We will now look at how to get Git installed on the system.

System Requirements

Memory 2 GB RAM (recommended)
Disk Space 200 MB HDD for the installation. Additional storage is requicrimson to store the project source code and this particular particular is dependent on the source code end up beinging added.
Operating System Version Can end up being installed on Windows, Ubuntu/Debian, Red Hat/Fedora/CentOS, Mac OS X.

Installing Git

Step 1 − The awayicial website for Git is /index.php?s=httpsgit-scmcom. If you click on the link, you will get to the home page of the Git awayicial website as shown in the folloearng screenshot.

Official Website

Step 2 − To download Git, simply scroll down the screen and go to the Downloads section and click Downloads.

Downloads Section

Step 3 − Click the Windows link and the download for Git will end up beinggin automatically.

GIT

Step 4 − Click the downloaded .exe file for Git. In our case, we are using the Git-2.6.1-64-bit.exe file. Click Run which comes appears on the next screen.

Exe File

Step 5 − Click the Next button that appears on the folloearng screen.

Next Button

Step 6 − Click Next in the folloearng screen to accept the General License concurment.

General License concurment.

Step 7 − Choose the location for your own Git installation.

GIT Installation

Step 8 − Click Next to accept the default components that are need to end up being installed.

Default Components

Step 9 − Choose the option of ‘Use Git from the Windows command prompt’ since we are going to end up being using Git from Windows.

Git From Windows

Step 10 − In the folloearng screen, accept the default setting of ‘Checkaway generally generally there Windows-style, commit Unix-style collection endings’ and click Next.

Check away generally generally there Windows Style

Step 11 − In the folloearng screen, select the option of ‘Use Windows default console earndow’, since we are using Windows as the system for installation of Git.

Default Console Window

The installation will now start, and the subsequent steps can end up being followed for configuring Git, once the installation is comppermite.

Finish

Configuring Git

Once Git has end up beingen installed, the configuration steps need to end up being carried away generally generally there for the preliminary configuration of Git.

The 1st slimg that needs to end up being done is to configure the identity in Git and then to configure a user name and email. This is imslotant end up beingcause every Git commit uses this particular particular information, and it’s immutably baked into the commit is you start creating. One can do this particular particular by open uping the command prompt and then enter the folloearng commands −

git config –global user.name “Username”
git config –global user.email “emailid”

The folloearng screenshot is an example for end up beingtter understanding.

Administrator Command Prompt

These commands will behaveually alter the configuration file of Git accordingly. To ensure your own settings have conaspectrn effect, you can list down the settings of the Git configuration file by using issuing the folloearng command.

git config --list

An example of the away generally generally thereput is shown in the folloearng screenshot.

Example Output

Continuous Integration Server

The next crucial smoothware requicrimson for the entire continuous integration pipecollection is the Continuous Integration smoothware it iself. Folloearng are the the majority of commonly used Continuous Integration smoothwares used in the indusattempt −

  • Jenkins− This is an open up source Continuous Integration smoothware which is used by a lot of makement commdeviceie ups.

  • Jet Brains TeamCity − This is one of the the majority of popular commercial Continuous Integration smoothware’s available and the majority of companies use this particular particular for their particular particular Continuous Integration needs.

  • Atlbumian Bamboo − This is one more popular Continuous Integration smoothware provided by a company kind of called Atlbumian Pvt. Ltd.

All of the smoothwares mentioned above, work on the exbehave same model for Continuous Integration. For the purpose of this particular particular tutorial, we will look at Jetbrains TeamCity for the Continuous Integration server.

Installing TeamCity

Folloearng are the steps and the system requirements for installing Jet Brains TeamCity in your own computer.

System Requirements

Memory 4 GB RAM (recommended)
Disk Space 1 GB HDD for the installation. Additional storage is requicrimson to store the make workspace for every project.
Operating System Version Can end up being installed on Windows, Linux, Mac OS X.

Installation

Step 1 − The awayicial website for TeamCity is/index.php?s=httpswwwjetbrainscomteamcity. If you click the given link, you will go to the home page of the TeamCity awayicial website as shown in the folloearng screenshot. You can brangese the page to download the requicrimson smoothware for TeamCity.

Official Website of Teamcity

Step 2 − The downloaded .exe is end up beinging used for the purpose of executing TeamCity-9.1.6.exe. Double-click the executable and then click Run in the next screen that pops up.

Run TeamCity

Step 3 − Click Next to start the setup.

TeamCity Setup Wizard

Step 4 − Click the ‘I Agree’ button to accept the license concurment and proceed with the installation.

I Agree Button

Step 5 − Choose the location for the installation and click Next.

Destination Folder

Step 6 − Choose the default components for the installation and click Next

Default Components TeamCity Setup

This will start the installation process. Once comppermited the configuration process will follow.

Step 7 − Choose a slot numend up beingr for the server to operate. Best is to use a various slot such as 8080.

Port Numend up beingr

Step 8 − Next it will ask for which account TeamCity needs to operate as. Choose the SYSTEM account and Click Next.

System Account

Step 9 − Next it will ask for the services which needs to end up being started. Accept the default ones and then click Next.

Setup Services

Configuring TeamCity

Once the installation is comppermite, the next step is the configuration of TeamCity. This smoothware can end up being open uped by brangesing on the folloearng URL in the brangeser −

http://locahost:8080

Step 1 − The 1st step is to provide the location of the makes, which will end up being carried away generally generally there by TeamCity. Choose the desicrimson location and click the Proceed button.

Location of the Builds

Step 2 − The next step is to specify the database for storing all the TeamCity artefbehaves. For the purpose of the tutorial, one can select the Internal (HSQLDB), which is an internal database that is end up beingst suited when using items for checking purposes.

Internal Database

TeamCity will then process all the essential steps to get it up and operatening.

Step 3 − Next you will end up being requested to Accept the license concurment. Accept the exbehave same and click Continue.

Accept License Agreement

Step 4 − You need to make an administrator account that will end up being used to log into the TeamCity smoothware. Enter the requicrimson details and click the ‘Create Account’ button.

TeamCity Create Account Button

You will now end up being logged into TeamCity.

TeamCity Login

The Build Tool

The Build tool is a tool which ensures that the program is built in a particular way. The tool will normally carry away generally generally there a list of tasks, which are requicrimson for the program to end up being built in a proper manner. Since in our example, we are going to end up being looruler at a .Net program , we will end up being looruler at MSBuild as the make tool. The MSBuild tool looks at a make file which contains a list of tasks that are used to make the project. Let’s look at a typical Build file for a web configuration project.

Folloearng are the key sections of the Build file, which need to end up being conpartcrimson.

IIS Settings

Folloearng settings are used to determine which is the slot numend up beingr, what is the rawaye on the web server and what kind of authentication is requicrimson when the application is operate. These are imslotant settings, which will end up being alterd via the MSBuild command when we understand how the deployment will end up being carried away generally generally there later on in the tutorial.

<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPor>
<DevelopmentServerPort>61581</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:61581/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>

ItemGroup

This is used to tell the Build server what are all the dependent binaries that are requicrimson to operate this particular particular project.

<ItemGroup>
   <Reference Include = "System.Web.ApplicationServices" />
   <Reference Include = "System.ComponentModel.DataAnnotations" />

<ItemGroup>
   <Compile Include = "App_StartBundleConfig.cs" />
   <Compile Include = "App_StartFilterConfig.cs" />

.Net Framework Version

The TargetFrameworkVersion tells which is the version of .Net that needs to end up being present for the project to work. This is absolutely requicrimson end up beingcause if the make server does not have this particular particular in place, the make will fail.

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

Deployment Environment – Amazon

For the purpose of this particular particular tutorial, we will ensure our Continuous Integration server has the capability to deploy our application to Amazon. For this particular particular, we need to ensure the folloearng artefbehaves are in place.

Database Server

Perform the folloearng steps to ensure that the database server is wislim place in Amazon for the deployment.

Step 1 − Go to the Amazon Console − /index.php?s=httpsawsamazoncomconsole.

Login with your own ccrimsonentials. Note that you can apply for a free id on the amazon site, which will permit you to have a free link upr that permit’s you to use some of the resources on Amazon free of cost.

AWS Management Console

Step 2 − Go to the RDS Section to make your own database.

RDS Section

Step 3 − Click Instances in the next screen that pops up.

Instances

Step 4 − Click the Launch DB option in the next screen that comes up.

Launch DB

Step 5 − Choose the SQL Server tab and then select the Select option for SQL Server Express.

SQL Server Tab

Step 6 − Ensure that the folloearng details are entecrimson to confirm that you are using the free link upr of databases available from Amazon.

Free Tier of DataBases

Step 7 − Click the Next Step button once all the fields are filled.

Next Button AWS Console

Step 8 − In the next screen that comes up, accept all the default settings and Click Launch DB Instance.

Launch DB Instance

Step 9 − You will then end up being presented with a screen that says that the DB is end up beinging successcompletey launched. On the exbehave same page, generally generally there will end up being a button to watch the DB Instance. Click the link to see your own DB Instance end up beinging set up.

DB Launched

DB Instance Creation

After some time, the status of the above screen will alter to notify that the DB Instance has end up beingen successcompletey maked.

Web Server

The next step is to make your own web server on Amazon, which will host the web application. This can end up being done by folloearng the subsequent steps to have this particular particular in place.

Step 1 − Go to Amazon Console − /index.php?s=httpsawsamazoncomconsole.

Login with your own ccrimsonentials. Note that you can apply for a free id on the Amazon site, which will permit you to have a free link upr that permit’s you to use some of the resources on Amazon free of cost.

Login

Step 2 − Go to the EC2 section to make your own web server.

EC2 Section

Step 3 − In the next screen, click Launch Instance.

Launch Instance

Step 4 − Click Windows – Microsmooth Windows Server 2010 R2 Base.

Microsmooth Windows Server 2010 R2 Base

Step 5 − Choose the t2.micro option, which is a part of the free link upr. Click Next: Configure Instance Details.

T2 Micro Option

Step 6 − Accept the default settings on the next screen that comes up and then select the option Next: Add Storage.

Next Add Storage

Step 7 − Accept the default settings on the next screen and select the option Next: Tag Instance.

Next Tag Instance

Step 8 − Accept the default settings on the next screen and select the option of Next: Configure Security Group.

Next Configure Security Group

Step 9 − Accept the default settings on the next screen and select the option of Rewatch and Launch.

Rewatch and Launch

Step 10 − Click Launch in the next screen that comes up.

Launch

Step 11 − In the next screen that comes up, you will end up being prompted to make a key pair. This will end up being used to log into the server at a later stage of time. Just make the key pair and click Launch Instance.

Key Pair Launch Instance

The instance will now end up being set up in Amazon.

Continuous Integration – Reducing Risks

There are chances that slimgs will go inproper on a project. By effectively prbehaveicing CI, you find away generally generally there what happens at every step along the way, instead than later when the project is wislimto the makement cycle. CI helps you identify and mitigate risks when they occur, maruler it easier to evaluate and reslot on the health of the project based on concrete evidence.

This section is going to concentrate on the risks that can end up being avoided by using Continuous Integration.

On any kind of project, generally generally there are many kind of risks that need to end up being managed. By eliminating the risks earsitr in the makement lifecycle, generally generally there are lesser chances of these risks makeing into issues later on, when the system behaveually goes reaspect.

Risk 1 – Lack of Deployable Software

“It works on my machine but does not work on one more” – This is probably one of the the majority of common phrases encountecrimson in any kind of smoothware body organization. Because of the numend up beingr of alters done to smoothware makes on a daily basis, occasionally generally generally there is small confidence on whether the make of the smoothware behaveually works or not. This concern has the folloearng three part effects.

  • Little or no confidence in whether we can behaveually make the smoothware.

  • Lengthy integration phases end up beingfore dereaspectring the smoothware internally (i.e., check team) or externally (i.e., customer), during which time absolutely noslimg else gets done.

  • Incapability to produce and reproduce checkable makes.

Solution

Eliminating limited coupling end up beingtween the IDE and the make processes. Use a separate machine solely for integrating the smoothware. Ensure that everyslimg you need to make the smoothware is contained in the version manage repository. Finally, make a Continuous Integration system.

The Continuous Integration server can watch for alters in the version manage repository and operate the project make script when it detects a alter to the repository. The capcapability of the Continuous Integration system can end up being incrreare locatedved to include having the make operate through checks, perform inspections, and deploy the smoothware in the makement and check environments; this particular particular way you always have a worruler smoothware.

“Incapability to synchronize with the database” – Sometimes makeers are unable to remake the database fastly during makement, and hence find it difficult to make alters. Often this particular particular is because of to a separation end up beingtween the database team and the makement team. Each team will end up being focused on their particular particular own responsibililink ups and have small collaboration end up beingtween every other. This concern has the folloearng three part effects −

  • Fear of maruler alters or refbehaveoring the database or source code.

  • Difficulty in populating the database with various sets of check data.

  • Difficulty in maintaining makement and checking environments (e.g., Development, Integration, QA, and Test).

Solution

The solution to the above issue is to ensure that the placement of all database artifbehaves in the version manage repository are carried away generally generally there. This means everyslimg that is requicrimson to remake the database schema and data: database creation scripts, data manipulation scripts, stocrimson procedures, triggers, and any kind of other database bumets are needed.

Remake the database and data from your own make script, by fallping and recreating your own database and tables. Next, apply the stocrimson procedures and triggers, and finally, insert the check data.

Test (and inspect) your own database. Typically, you will use the component checks to check the database and data. In some cases, you’ll need to write database-specific checks.

Risk 2 – Discovering Defects Late in the Lifecycle

Since generally generally there are so many kind of alters which happen regularly by multiple makeers to the source code, generally generally there are always chances that a defect can end up being introduced in the code that could only end up being detected at a later stage. In such cases, this particular particular can cause a huge impbehave end up beingcause the later the defect is detected in the smoothware, the more expensive it end up beingcomes to remove the defect.

Solution

Regression Testing − This is the the majority of imslotant aspect of any kind of smoothware makement cycle, check and check again. If generally generally there is any kind of major alter to the smoothware code, it is absolutely mandatory to ensure that all the checks are operate. And this particular particular can end up being automated with the help of the Continuous Integration server.

Test Coverage − There is no stage in checking if the check cases do not cover the entire functionality of the code. It is imslotant to ensure that the check cases maked to check the application are comppermite and that all code rawayes are checked.

For example, if you have a login screen which needs to end up being checked, you simply can’t have a check case that has the scenario of a successful login. You need to have a negative check case wherein a user enters a various combination of user names and comppermitewords and then it is requicrimson to see what happens in such scenarios.

Risk 3 – Lack of Project Visibility

Manual communication mechanisms require a lot of coordination to ensure the dissemination of project information to the proper people in a timely manner. Leaning over to the makeer next to you and permitting them know that the lacheck make is on the shacrimson drive is wislimstead effective, yet it doesn’t level very well.

What if generally generally there are other makeers who need this particular particular information and they are on a break or otherwise unavailable? If a server goes down, how are you notified? Some end up beingsitve they can mitigate this particular particular risk by manually sending an e-mail. However, this particular particular cannot ensure the information is communicated to the proper people at the proper time end up beingcause you may accidentally depart away generally generally there attentioned parlink ups, and some may not have access to their particular particular e-mail at the time.

Solution

The Solution to this particular particular issue is again the Continuous Integration server. All CI servers have the facility to have automated emails to end up being triggecrimson whenever the makes fail. By this particular particular automatic notification to all key sconaspectrholders, it is furthermore ensucrimson that everyone is on panel on what is the current state of the smoothware.

Risk 4 – Low Quality Software

There are defects and then generally generally there are possible defects. You can have possible defects when your own smoothware is not well designed or if it is not folloearng the project standards, or is complex to maintain. Sometimes people refer to this particular particular as code or design odors — “a symptom that someslimg may end up being inproper.”

Some end up beingsitve that lower-quality smoothware is solely a defercrimson project cost (after dereaspecattempt). It can end up being a defercrimson project cost, but it furthermore leads to many kind of other issues end up beingfore you dereaspectr the smoothware to the users. Overly complex code, code that does not follow the architecture, and duplicated code – all usually lead to defects in the smoothware. Finding these code and design odors end up beingfore they manifest into defects can save both time and money, and can lead to higher-quality smoothware.

Solution

There are smoothware components to carry away generally generally there a code quality check which can end up being integrated with the CI smoothware. This can end up being operate after the code is built to ensure that the code behaveually conforms to proper coding guidecollections.

Continuous Integration – Version Control

Version manage systems, furthermore known as source manage, source code management systems, or revision manage systems, are a mechanism for maintaining multiple versions of your own files, so that when you modify a file you can still access the previous revisions.

The 1st popular version manage system was a proprietary UNIX tool called SCCS (Source Code Control System) which dates back to the 1970s. This was superseded by RCS, the Revision Control System, and later CVS, Concurrent Versions System.

Now the the majority of popular version manage system used are Subversion and Git. Let’s 1st look at why we need to use a versioning manage system and next permit’s look at putting our source code in Git source code repository system.

Purpose of the Version Control System

One reason that we use the term version manage in preference to source manage is that version manage isn’t simply for source code. Every single artifbehave related to the creation of your own smoothware need to end up being under version manage.

    Developers need to use it for source code − By default all source code needs to end up being stocrimson in the versioning manage system

    Related artefbehaves − Every system would end up being having related artefbehaves to the source code such as database scripts, make and deployment scripts, documentation, libraries and configuration files for your own application, your own compiler and collection of tools, and so on. All of these compliment the entire makement and deployment process and furthermore needs to end up being stocrimson in the versioning manage system.

By storing all the information for the application in source manage, it end up beingcomes easier to re-make the checking and itemion environments that your own application operates on. This need to include configuration information for your own application’s smoothware stack and the operating systems that comprise the environment, DNS Zone Files, Firewall Configuration, and so forth.

At the bare minimum, you need everyslimg requicrimson to re-make your own application’s binaries and the environments in which they operate. The goal is to have everyslimg that can possibly alter at any kind of stage in the life of the project stocrimson in a manageled manner. This permit’s you to recover an exbehave snapshot of the state of the entire system, from makement environment to itemion environment, at any kind of stage in the project’s background.

It is behaveually helpful to maintain the configuration files for the makement team’s makement environments in version manage since it makes it easy for everyone on the team to use the exbehave same settings. Analysts need to store requirements documents. Testers need to maintain their particular particular check scripts and procedures in version manage. Project managers need to save their particular particular relreare locatedve plans, progress charts, and risk logs here.

In short, every memend up beingr of the team need to store any kind of document or file related to the project in version manage.

Worruler with Git for Source Code Versioning Control System

This section will now focus on how Git can end up being used as a versioning manage system. It will focus on how you can upload your own code to the versioning manage system and manage alters in it.

Our Demo Application

For the purpose of this particular particular entire tutorial we are going to look at a easy Web ASP.Net application which will end up being used for the entire Continuous Integration Process. We don’t need to focus on the entire code details for this particular particular exercise, simply having an overwatch of what the project does is sufficient for understanding the entire continuous integration process. This .Net application was built using the Visual Studio Integrated Development Environment.

The folloearng screenshot is the structure of the solution in the Visual Studio environment. It is an extremely easy Web application which has the main code in the Demo.aspx file.

Demo ASPX

The code in the Demo.aspx file is shown in the folloearng program −

<html xmlns = "http://www.w3.org/1999/xhtml">
   <mind operateat = "server">
      <title>TutorialsPoint</title>
   </mind>
   
   <body>
      <form id = "form1" operateat="server">
         <div><%Response.Write("Continuous Integration"); %></div>
      </form>
   </body>
   
</html>

The code is very easy and simply away generally generally thereputs the string “Continuous Integration” to the brangeser.

When you operate the project in Google Chrome, the away generally generally thereput will end up being as shown in the folloearng screenshot.

Run the Project

Moving Source Code to Git

We are going to show how to move the source code to Git from the command collection interface, so that the knowladvantage of how Git can end up being used is clearer to the end user.

Step 1 − Initialize the Git Repository. Go to the command prompt, go to your own project folder and issue the command git init. This command will add the essential Git files to the project folder, so that it can end up being recognised by Git when it needs to end up being uploaded to the repository.

GIT Repository

Step 2 − Adding your own files which need to end up being added to the Git repository. This can end up being done by issuing the git add command. The dot option tells Git that all files in the project folder need to end up being added to the Git repository.

GIT Add Command

Step 3 − The final step is to commit the project files to the Git repository. This step is requicrimson to ensure all files are now a part of Git. The command to end up being issued is given in the folloearng screenshot. The –m option is to provide a comment to the upload of files.

-M Option

Your solution is now available in Git.

Continuous Integration – Features

Folloearng are some of the main features or prbehaveices for Continuous Integration.

  • Maintain a single source repository − All source code is maintained in a single repository. This avoids having source code end up beinging scattecrimson acombination multiple locations. Tools such as Subversion and Git are the the majority of popular tools for maintaining source code.

  • Automate the make − The make of the smoothware need to end up being carried away generally generally there in such a way that it can end up being automated. If generally generally there are multiple steps that need to end up being carried away generally generally there, then the make tool needs to end up being capable of doing this particular particular. For .Net, MSBuild is the default make tool and for Java based applications you have tools such as Maven and Goperatet.

  • Make your own make self-checking − The make need to end up being checkable. Directly after the make occurs, check cases need to end up being operate to ensure that checking can end up being carried away generally generally there for the various functionality of the smoothware.

  • Every commit need to make on an integration machine − The integration machine is the make server and it need to end up being ensucrimson that the make operates on this particular particular machine. This means that all dependent components need to exist on the Continuous Integration server.

  • Keep the make fast − The make need to happen in moments. The make need to not conaspectr hours to happen, end up beingcause this particular particular would mean the make steps are not properly configucrimson.

  • Test in a csingle of the itemion environment − The make environment need to end up being near in character to the itemion environment. If generally generally there are vast differences end up beingtween these environments, then generally generally there can end up being a case that the make may fail in itemion behaveually though it comppermitees on the make server.

  • Everyone can see what is happening − The entire process of make and checking and deployment need to end up being noticeable to all.

  • Automate deployment − Continuous Integration leads to Continuous deployment. It is absolutely essential to ensure that the make need to end up being easy to deploy onto possibly a staging or itemion environment.

Continuous Integration – Requirements

Folloearng is the list of the the majority of substantial requirements for Continuous Integration.

  • Check-In Regularly − The the majority of imslotant prbehaveice for continuous integration to work properly is regular check-ins to toperatek or maincollection of the source code repository. The check-in of code need to happen at leasternern a couple of times a day. Checruler in regularly brings lots of other end up beingnefit is. It makes alters smaller and thus less likely to break the make. It means the latest the majority of version of the smoothware to revert to is known when a misconaspectr is made in any kind of subsequent make.

    It furthermore helps to end up being more discipcollectiond abaway generally generally there refbehaveoring code and to stay to small alters that preserve end up beinghavior. It helps to ensure that alters altering a lot of files are less likely to conflict with other people’s work. It permit’s the makeers to end up being more explorative, attempting away generally generally there ideas and discarding them by reverting back to the final committed version.

  • Create a Comprehensive Automated Test Suite − If you don’t have a extensive suite of automated checks, a comppermiteing make only means that the application could end up being compiled and bumembled. While for some teams this particular particular is a huge step, it’s essential to have some level of automated checking to provide confidence that your own application is behaveually worruler.

    Normally, generally generally there are 3 kinds of checks conducted in Continuous Integration namely device checks, component checks, and acceptance checks.

    Unit checks are maked to check the end up beinghavior of small pieces of your own application in isolation. They can usually end up being operate withaway generally generally there starting the whole application. They do not hit the database (if your own application has one), the filesystem, or the ne2rk. They don’t require your own application to end up being operatening in a itemion-like environment. Unit checks need to operate very fast — your own whole suite, behaveually for a big application, need to end up being able to operate in under ten moments.

    Component checks check the end up beinghavior of some components of your own application. Like device checks, they don’t always require starting the whole application. However, they may hit the database, the filesystem, or other systems (which may end up being stubend up beingd away generally generally there). Component checks typically conaspectr longer to operate.

  • Keep the Build and Test Process Short − If it conaspectrs too long to make the code and operate the device checks, you will operate into the folloearng issues.

    • People will end doing a complete make and will operate the checks end up beingfore they check-in. You will start to get more failing makes.

    • The Continuous Integration process will conaspectr so long that multiple commit is would have conaspectrn place by the time you can operate the make again, so you won’t know which check-in broke the make.

    • People will check-in less usually end up beingcause they have to sit around for ages wait arounding for the smoothware to make and the checks to operate.

  • Don’t Check-In on a Broken Build − The hugegest blunder of continuous integration is checruler in on a broken make. If the make breaks, the makeers responsible are wait arounding to fix it. They identify the cause of the breakage as soon as achievable and fix it. If we adopt this particular particular strategy, we will always end up being in the end up beingst position to work away generally generally there what caused the breakage and fix it immediately.

    If one of our colleagues has made a check-in and has as a result broken the make, then to have the end up beingst chance of fixing it, they will need a clear operate at the issue. When this particular particular rule is broken, it inevitably conaspectrs a lot longer for the make to end up being fixed. People get used to seeing the make broken, and very fastly you get into a situation where the make stays broken all of the time.

  • Always Run All Commit Tests Locally Before Committing − Always ensure that the checks designed for the application are operate 1st on a local machine end up beingfore operatening them on the CI server. This is to ensure the proper check cases are maked and if generally generally there is any kind of failure in the CI process, it is end up beingcause of the failed check results.

  • Take Responsibility for All Breakages that Result from Your Changes − If you commit a alter and all the checks you wrote comppermite, but others break, the make is still broken. Usually this particular particular means that you have introduced a regression bug into the application. It is your own responsibility — end up beingcause you made the alter — to fix all checks that are not comppermiteing as a result of your own alters. In the context of CI this particular particular seems obvious, but behaveually it is not a common prbehaveice in many kind of projects.

Continuous Integration – Building a Solution

There are a variety of make tools available for a variety of programming languages. Some of the the majority of popular make tools include Ant for Java and MSBuild for .NET. Using a scripting tool designed specifically for makeing smoothware, instead of a custom set of shell or batch scripts, is the the majority of effective manner for makeing a consistent, repeatable make solution.

So why do we need a make process to start with. Well for starters, for a Continuous Integration server, the make process need to end up being easy to work with and need to end up being oceanmless to implement.

Let’s conaspectr a easy example of what a make file can look like for .Net −

<?xml version = "1.0" encoding = "utf-8"?>
<project xmlns = "http://schemas.microsmooth.com/makeer/msmake/2003">
   <Target Name = "Build">
      <Message Text = "Building Project" />
      <MSBuild Projects = "project.csproj" Targets = "Build/>"
   </Target>
</project>

The folloearng aspects need to end up being noted abaway generally generally there the above code −

  • A target is specified with a name of the Build. Wherein, a target is a collection of logical steps which need to end up being performed in a make process. You can have multiple targets and have dependencies end up beingtween targets.

  • In our target, we maintain an option message which will end up being shown when the make process starts.

  • The MSBuild task is used to specify which .Net project needs to end up being built.

The above example is a case of an extremely easy make file. In Continuous Integration, it is ensucrimson that this particular particular file is kept up-to-date to ensure that the entire make process is oceanmless.

Building a Solution in .Net

The default make tool for .Net is MSBuild and is someslimg that comes shipped with the .Net framework. Depending on the framework on your own system, you will have the relevant MSmake version available. As an example, if you have the .Net framework installed in the default location, you will find the MSBuild.exe file in the folloearng location −

C:WindowsMicrosmooth.NETFrameworkv4.0.30319

Let’s see how we can go abaway generally generally there makeing our sample project. Let’s bumume our Sample project is located in a folder called C:DemoSimple.

In order to use MSBuild to make the above solution, we need to open up the command prompt and use the MSBuild option as shown in the folloearng program.

msmake C:DemoSimpleSimple.csproj

In the above example, csproj is the project file which is specific to .Net. The csproj file contains all the relevant information to ensure that the requicrimson information is present for the smoothware to make properly. Folloearng is the screenshot of the away generally generally thereput of the MSBuild command.

MS Build Command

You don’t need to worry abaway generally generally there the away generally generally thereput warnings as long as the Build was successful and generally generally there were no errors.

Continuous Integration – Build Scripts

Now permit’s look at particular aspects of the MSBuild file to see what they mean. These aspects are imslotant to know from a Continuous Integration Cycle.

Build scripts are used to make the solution which will end up being a part of the entire continuous Integration cycle. Let’s look at the general make script which is maked as a part of Visual Studio in .Net for our sample solution. The make script is a fairly huge one, behaveually for a easy solution, so we will go through the the majority of imslotant parts of it. By default, the make script will end up being stocrimson in a file with the exbehave same name as the main solution in Visual Studio. So in our case, if you open up the file Simple.csproj, you will see all the settings which will end up being used to make the solution.

  • Dependency on the MSBuild version used − The folloearng settings will use the MSBuild files installed on the CI server.

<VisualStudioVersion Condition = "'$(VisualStudioVersion)' == 
   ''">10.0</VisualStudioVersion>

<VSToolsPath Condition = "'$(VSToolsPath)' == ''"> 
   $(MSBuildExtensionsPath32)MicrosmoothVisualStudiov$(VisualStudioVersion)
</VSToolsPath>

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>

<Imslot Project = "$(MSBuildBinPath)Microsmooth.CSharp.targets" />
<Imslot Project = "$(VSToolsPath)WebApplications
   Microsmooth.WebApplication.targets" Condition = "'$(VSToolsPath)' ! = ''" />

<Imslot Project = "$(MSBuildExtensionsPath32)MicrosmoothVisualStudiov10.0
   WebApplicationsMicrosmooth.WebApplication.targets" Condition = "false" />
  • What files are requicrimson to make the solution properly – The ItemGroup tag will contain all the essential .Net files which are requicrimson for the project to make successcompletey. These files will need to repart on the make server accordingly.

<ItemGroup>
   <Reference Include = "Microsmooth.CSharp" />
   <Reference Include = "System.Web.DynamicData" />
   <Reference Include = "System.Web.Entity" />
   <Reference Include = "System.Web.ApplicationServices" />
   <Reference Include = "System.ComponentModel.DataAnnotations" />
   <Reference Include = "System" />
   <Reference Include = "System.Data" />
   <Reference Include = "System.Core" />
   <Reference Include = "System.Data.DataSetExtensions" />
   <Reference Include = "System.Web.Extensions" />
   <Reference Include = "System.Xml.Linq" />
   <Reference Include = "System.Draearng" />
   <Reference Include = "System.Web" />
   <Reference Include = "System.Xml" />
   <Reference Include = "System.Configuration" />
   <Reference Include = "System.Web.Services" />
   <Reference Include = "System.EnterpriseServices"/>
</ItemGroup>
  • What are the Web server settings to end up being used − When we visit our topic of Continuous Deployment, you will see how MSBuild will end up being used to override these settings and deploy this particular particular to our server of choice.

<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>59495</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl></IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>

CI – Building On the Server

The next imslotant step is to ensure that the solution makes on the make server. The 1st part is a manual step, end up beingcause end up beingfore the continuous integration tool is used, we 1st must ensure that the make gets operate on the make server in the exbehave same manner as what was done on the csitnt machine. To do this particular particular, we must implement the folloearng steps −

Step 1 − Copy the entire solution file to the server. We had maked an Amazon instance server which would end up being used as our make server. So, do a manual duplicate to the server of the entire .Net solution onto the server.

Manual Copy

Step 2 − Ensure that the framework is present on the server. If you have compiled your own application in .Net framework 4.0 on your own csitnt machine, you have to ensure that it is wislimstalled on the server machine as well. So go to the location C:WindowsMicrosmooth.NETFramework on your own server and ensure the desicrimson framework is present.

Framework Location

Step 3 − Now permit’s simply operate MSBuild on the server and see what happens.

MS Build

Ok, so it looks like we have hit an error. There is one imslotant lesson in Continuous Integration and that is you need to ensure that the Build works on the make server. For this particular particular you need to ensure that all prerequisite smoothware is wislimstalled on the make server.

For .Net, we need to install a component called Visual Studio Redistributable package. This package contains all the essential files which are requicrimson for a .Net application to make on a server. So permit’s carry away generally generally there the folloearng installation steps on the make server.

Step 4 − Double-click the executable file to start the installation.

Double Click to Start Installation

Step 5 − In the next step, concur to the License Terms and click Install.

License Terms

Step 6 − Now when operatening MSBuild, we need to ensure that we include an additional parameter when calling MSBuild which is – p:VisualStudioversion = 12.0. This ensures that MSBuild references those files that were downloaded in the earsitr step.

Running MsBuild

Now we can see that the solution has end up beingen built properly and we furthermore know our basecollection project makes properly on the server.

CI – Checruler in Source Code

The next key aspect is to ensure our basecollection code is checked into our source code repository management server which is Git. To do this particular particular, we need to follow these steps.

Step 1 − Initialize the repository so that it can end up being uploaded to Git. This is done with the git init command. So you need to go to your own project folder and issue the git init command.

GIT init Command

Step 2 − The next step is called staging files in Git. This prepares all the files in the project folder, which need to end up being added to Git. You do this particular particular with the git add command as shown in the folloearng screenshot. The ‘.’ notation is used to say that all files in the immediateory and subimmediateory need to end up being included in the commit.

Staging Files

Step 3 − The final step is to commit the files to the Git repository, so that it is now a complete-fladvantaged Git repository.

Full Fladvantaged Git Repository

CI – Creating a Project in TeamCity

Now that we have our source code in the Git repository and all of our preliminary code works on the make server, it is time to make a project in our Continuous Integration server. This can end up being done via the folloearng steps −

Step 1 − Login to the TeamCity smoothware. Go to the url on your own Continuous Integration server − http://localhost:8080/login.html.

TeamCity Software

Enter the admin ccrimsonentials and login to the server.

Step 2 − Once logged in, you will end up being presented with the home screen. Click Create Project to start a brand brand new project.

Create Project

Step 3 − Give a name for the project and click Create to start the project. In our case, we are giving the name as ‘Demo’ to our project as shown in the folloearng screenshot.

Project Name Demo

Step 4 − The next step is to mention the Git repository which will end up being used in our project. Rememend up beingr that in a Continuous Integration environment, the CI server needs to pick up the code from the Git enabled repository. We have already enabled our project folder to end up being a Git enabled repository in the earsitr step. In TeamCity, you need to make a VCS main. For this particular particular, click VCS Roots in the project’s main screen.

VCS Root

Step 5 − In the screen that comes up next, click Create VCS main as shown in the folloearng screenshot.

Create VCS Root

Step 6 − In the next screen that comes up, perform the folloearng steps −

  • Mention the kind of VCS as Git.

  • Give a name for the VCS main, this particular particular can end up being any kind of friendly name. We have given the name as App.

  • Give the Fetch url as C:DemoSimple – This is away generally generally there git enabled repository.

  • If you scroll down the screen, you will get a Test interinterconnection button. Click it to ensure that you can successcompletey connect to the Git enabled repository.

Test Connection Button

Test Connection Button Appears

Step 7 − Click Create and you will now see your own repository registecrimson as shown in the folloearng image.

Repository Registecrimson

Step 8 − The next step is to make a make configuration which will end up being used to make the project. Go to your own project screen in TeamCity → General Settings. Click Create Build Configuration.

Team City General settings

Step 9 − In the folloearng screen, give a name for the Build Configuration. In our case we have named it as DemoBuild and then click Create.

Demo Build

Step 10 − In the next screen that comes up, you will end up being asked to select the VCS repository which was maked in the earsitr steps. So select the name ‘App’ and click Attach.

VCS Repository

Step 11 − Now in the next screen that pops up, we need to configure the make steps. So click the ‘configure make steps manually’ hyperlink.

Configure Build Steps Manually

Step 12 − In the next make screen, we need to enter the folloearng details −

  • Choose the Runner kind as MSBuild.

  • Give an optional name for the step name.

  • Give the name of the file which needs to end up being built. When we specify MSmake in the earsitr sections, we normally see that we give the option of Simple.csproj. The exbehave same slimg is needed to end up being specified here.

  • Choose the MSBuild version as ‘Microsmooth Build Tools 2013’.

  • Choose the MSBuild ToolsVersion as 12.0.

  • Scroll down the page to Save the settings.

MS Build Tool Version

MS Build Tool Version 12.0

Step 13 − In the next screen, click Run.

Click Run

You will see the make of your own application now in progress.

Application in Progress

You need to get a successful screen, which is a great sign that your own solution is makeing properly.

Successful Screen

You can furthermore go to your own make log to see all the steps that were covecrimson by the Continuous Integration server as shown in the folloearng screenshot.

Continuous Integration Server

Continuous Integration – Defining Tasks

Now that we have our base code in Git and a link to the Continuous Integration server, it is finally time to see the 1st step of Continuous Integration in behaveion. This is done by defining tasks in the Continuous Integration server such as triggers, which makes the entire Continuous Integration Process as oceanmless as achievable. Let’s make a alter to our code in Visual Studio.

Step 1 − Go to the Demo.aspx page in Visual Studio and make a alter to the title of the page.

Demo.Aspx Page in Visual Studio

Step 2 − If we query our Git repository via the git status command, you will in fbehave see that the Demo.aspx file has end up beingen modified.

Git Status Command

Now we need to ensure that every alter in our code need to trigger a make in our continuous integration server. For this particular particular we need to do the folloearng alters.

Step 3 − Go to your own project dashpanel and click the triggers section and click Add brand brand new trigger.

Add New Trigger

Step 4 − In the next screen that comes up, select VCS trigger, which will end up being used to make a trigger so that when a check-in is made to the repository, a make will end up being triggecrimson.

VCS Trigger

Step 5 − Click Show Advanced Options and ensure the options shown in the folloearng screenshot are selected.

Show Advanced Options

Step 6 − Click Save. You will now see the trigger successcompletey registecrimson as shown in the folloearng screenshot.

Click and Save

Step 7 − Now it’s time to check in our code into the Git repository and see what happens. So permit’s go to our command prompt and issue the git add command to stage our alterd files.

Simple Git Add

Step 8 − Now issue the git commit command, and it will push the alters into the Git repository.

Step 9 − If you now go to your own Projects Overwatch screen, you will now see a brand brand new make would have end up beingen triggecrimson and operate.

New Build

If you see the Change log Tab, you will see the git comment which triggecrimson the make.

Change Log tab

Let’s attempt it one more time. Let’s make one more alter to the Demo.aspx file. Let’s carry away generally generally there a git add command and a git commit command with the folloearng commit message.

Git Add Git Command

Defining Tasks Demo Build

You will now see a make end up beinging automatically triggecrimson in the Project dashpanel in TeamCity.

Project Dashpanel TeamCity

The make will show a success message.

Success Message

You will now see the message of ‘Second commit’ which was used when the alter was committed to the git repository.

We have now successcompletey comppermited the 1st part of the Continuous Integration process.

CI – Build Failure Notifications

A Build Failure Notification is an behaveuallyt which is triggecrimson whenever a make fails. The notification is sent to all key people whenever a make fails. The 1st imslotant slimg to do in such a case is to ensure time is spent on the failed make to ensure the make comppermiteed. The folloearng steps are used to ensure that the make notifications are put in place in TeamCity.

Folloearng are the steps to set up email notifications in TeamCity.

Step 1 − In TeamCity, go to your own Project dashpanel, click on Administration in the top proper hand corner. You will then see the Email Notifier link in the left hand part. Click on this particular particular link to bring up the general settings for Email.

Email Notifier

Step 2 − Next step is to enter the details of a valid SMTP Server. Gmail provides a free SMTP facility, which can end up being used by any kind ofone. So we can enter those details in the next screen that comes up as shown in the folloearng screenshot.

  • SMTP Host – smtp.gmail.com
  • SMTP slot no – 465
  • Send email messages from and SMTP login – This need to end up being a valid Gmail id
  • SMTP comppermiteword – Valid comppermiteword for that Gmail id
  • Secure interinterconnection – Put this particular particular as SSL

SMPT Server

Step 3 − Click Test Connection simply to ensure that the settings are worruler properly. Then click Save to save the settings.

Step 4 − The next step is to enable make notifications for a user. The 1st task is to make a user which will receive these make notifications. Go to your own project dashpanel and select the Users Option.

Users Option

Step 5 − Create a brand brand new user. Enter the requicrimson username and comppermiteword. Then Click the Create User button, which will end up being located at the base level of the screen.

Create User Button

Step 6 − Now login to the TeamCity system with this particular particular brand brand new user id and comppermiteword.

Team City User Id and Pbumword

Step 7 − After you log in, you will end up being presented with the General settings of the user. In the Email Notifier section, click Edit.

General Settings of the User

Step 8 − In the next screen that comes up, click Add brand brand new rule.

Add New Rule

Step 9 − In Add brand brand new rule, select the folloearng 2 options and then click Save.

  • Builds from select projects – Choose the Demo project.

  • Enable the checkpackage for ‘Build fails’.

By enabling these 2 options, now whenever a make fails for the Demo project, an email notification will end up being sent to the user – demouser.

Demo Project

Step 10 − Now permit’s trigger a inproper make to see this particular particular in behaveion. In Visual Studio, go to the demo.aspx.cs file and add a inproper collection of code.

Demo ASPX Cs

Step 11 − Now check-in the code from Git by doing a git add and git commit.

Build Failure Git Add Command

Now in the Project Dashpanel, the make will automatically end up being triggecrimson and you will see that the make would have failed as shown in the folloearng screenshot.

Project Dashpanel Build Failure

If you login into the Gmail id of the demouser, you will behaveually see a make failure notification in it as shown in the folloearng screenshot.

Team City Build Failure

CI – Documentation and Feedback

One of the key aspects of Continuous Integration is always to see how the makes are performing, gathering imslotant metrics, documenting those away generally generally therecomes and generating continuous give food toback through continuous makes.

What are the end up beingnefit is of having these metrics in place?

  • Not Committing Code Enough − If makeers are not committing code to a version manage repository regularly, the reason may end up being a sluggish integration make. To end up beinggin to crimsonuce make duration, perform a high-level analysis of the integration make environment to determine the bottlenecks.

    Next, analyze the findings and determine the the majority of appropriate improvement, then attempt to make alters in the make process to crimsonuce the make’s duration. Lastly, reevaluate the make duration to determine if further improvements are warranted.

  • Improve Test Performance − Even in a well-functioning CI system, a bulk of the integration make time will end up being conaspectrn up by the execution of automated checks. Evaluating and improving the performance of these checks can dramatically crimsonuce make duration.

  • Infrastructure Issues − You may discover that integration makes are sluggish end up beingcause of the system infrastructure. Perhaps ne2rk performance is sluggish or generally generally there is a sluggish-performing virtual private ne2rk interinterconnection.

    Geographically dispersed systems and unreliable hardware or smoothware can furthermore induce performance issues. Investigate and improve any kind of infrastructure resources to crimsonuce the make duration.

Metrics

Folloearng are some of the metrics which are available in a Continuous Integration server.

Let’s look at what TeamCity has to awayer −

One of the easyst form of metrics is what is available in the project dashpanel. The key element here is to note the duration of every make. If the duration of every make starts increasing disproslotionally to the code end up beinging built, then this particular particular could end up being an issue. So, this particular particular is one give food toback that can end up being conaspectrn and the causes of this particular particular could end up being that the CI server is low on resources and mayend up being the capacity of the server needs to end up being incrreare locatedved.

Metrics

TeamCity has the facility to see if the CI server is wislim fbehave having any kind of sort of issues with regards to infrastructure. In the admin dashpanel in TeamCity, one can click on Disk Usage to see how a lot disk space is end up beinging consumed by every make.

Admin Dashpanel

If any kind of more details are requicrimson, then TeamCity has the diagnostics button, which can give more information on the CPU and Memory end up beinging utilized by the CI Server.

Diagnostics Button

Detailed View of Build Metrics

If one wants to see a detailed watch of the makes of a particular project over time, then this particular particular is available as a part of the project makes. In the Project make screen, go to the Statistics screen, this particular particular will provide various statistics and charts on how the make is performing.

Detailed View of Build Metrics

Continuous Integration – Testing

One of the key features of Continuous Integration is to ensure that the on-going checking holds all the code which gets built by the CI server. After a make is carried away generally generally there by the CI Server, it has to end up being ensucrimson that the check cases are in place to get the requicrimson code checked. Every CI server has the capability to operate device check cases as part of the CI suite. In .Net, the device checking is a feature which is wislimbuilt into the .Net framework and the exbehave same slimg can end up being incorporated into the CI Server as well.

This chapter will see how we can degood a check case in .Net and then permit our TeamCity server operate this particular particular check case after the make is comppermited. For this particular particular, we 1st need to ensure that we have a device check degoodd for our sample project.

To do this particular particular, we must follow the ensuing steps with utthe majority of carefulness.

Step 1 − Let’s add a brand brand new clbum to our solution, which will end up being used in our Unit Test. This clbum will have a name variable, which will hold the string “Continuous Integration”. This string will end up being displayed on the web page. Right-click on the Simple Project and select the menu option Add → Clbum.

Add Clbum

Step 2 − Give a name for the clbum as Tutorial.cs and click the Add button at the base level of the screen.

Tutorial CS

Step 3 − Open the Tutorial.cs file and add the folloearng code in it. This code simply makes a string called Name, and in the Constructor bumign the name to a string value as Continuous Integration.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Simple {
   public clbum Tutorial {
      public String Name;
      public Tutorial() {
         Name = "Continuous Integration";
      }
   }
}

Step 4 − Let us make the alter to our Demo.aspx.cs file to use this particular particular brand brand new clbum. Update the code in this particular particular file with the folloearng code. So this particular particular code will now make a brand brand new instance of the clbum maked above.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Simple {
   public partial clbum Demo : System.Web.UI.Page {
      Tutorial tp = brand brand new Tutorial();
      protected void Page_Load(object sender, EventArgs e) {
         tp.Name = "Continuous Integration";
      }
   }
}

Step 5 − In our demo.aspx file, permit us now reference the tp.Name variable, which was maked in the aspx.cs file.

<%@ Page Language = "C#" AutoEventWireup = "true" 
   CodeBehind = "Demo.aspx.cs" Inherit is = "Simple.Demo" %>
<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml">
   
   <mind operateat = "server">
      <title>TutorialsPoint1</title>
   </mind>
   
   <body>
      <form id = "form1" operateat = "server">
         <div>
            <% = tp.Name%>)
         </div>
      </form>
   </body>
   
</html>

Just to ensure our code works good with these alters, you can operate the code in Visual Studio. You need to get the folloearng away generally generally thereput once the compilation is comppermite.

Continuous Integration Output

Step 6 − Now it is time to add our Unit checks to the project. Right-click on Solution and select the menu option Add → New Project.

Right Click on Solution

Step 7 − Navigate to Test and on the proper hand part, select Unit Test Project. Give a name as DemoTest and then click OK.

Unit Test Project

Step 8 − In your own Demo Test project, you need to add a reference to the Simple project and to the essential checking bumembsit is. Right-click on the project and select the menu option Add Reference.

Add Reference

Step 9 − In the next screen that comes up, go to Projects, select Simple Reference and click OK.

Simple Reference

Step 10 − Click Add Reference again, go to Assembsit is and kind Web in the Search package. Then add a reference of System.Web.

System Web

Step 11 − In the Unit Test file, add the folloearng code. This code will ensure that the Tutorial clbum has a string name variable. It will furthermore bumert the fbehave that the Name need to equal a value of “Continuous Integration”. This will end up being our easy Test case.

using System;
using Microsmooth.VisualStudio.TestTools.UnitTesting;
using Microsmooth.VisualStudio.TestTools.UnitTesting.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Simple;

namespace DemoTest {
   [TestClbum]
   public clbum UnitTest1 {
      [TestMethod]
      public void TestMethod1() {
         Tutorial tp = brand brand new Tutorial();
         Assert.AreEqual(tp.Name, "Continuous Integration");
      }
   }
}

Step 12 − Now permit’s operate our check in Visual Studio to make sure it works. In Visual Studio, select the menu option Test → Run → All Tests.

Test Run Allchecks

After operatening the check, you will see the Test successcompletey operate on the left hand part of Visual Studio.

Test Successful

Enabling Continuous Testing wislim TeamCity – Now that all the check cases are in place, it is time to integrate these into our Team City server.

Step 13 − For this particular particular, we need to make a make step in our Project configuration. Go to your own project home and click Edit Configuration Settings.

Edit Configuration Settings

step 14 − Then go to Build Step → MS Build and click Add make step as depicted in the folloearng screenshot.

Build Step Ms Build

In the next screen that comes up, add the folloearng values −

  • Choose the operatener kind as Visual Studio Tests.

  • Enter an optional Test step name.

  • Choose the Test Engine kind as VSTest.

  • Choose the Test Engine version as VSTest2013.

  • In the Test files name, provide the location as DemoTestbinDebugDemoTest.dll – Rememend up beingr that DemoTest is the name of our project which contains our Unit Tests. The DemoTest.dll will end up being generated by our 1st make step.

  • Click Save which will end up being available at the end of the screen.

Save Button

Now you will have 2 make steps for your own project. The 1st is the Build step which will make your own application code and your own check project. And the next will end up being used to operate your own check cases.

Build steps

Step 15 − Now it is time to check-in all your own code in Git, so that the entire make process can end up being triggecrimson. The only difference is this particular particular time, you need to operate the git add and git commit command from the Demo parent folder as shown in the folloearng screenshot.

Demo Parent Folder

Now when the make is triggecrimson, you will see an preliminary away generally generally thereput which will say that the check comppermiteed.

Initial away generally generally thereput

Step 16 − If you click on the Test comppermiteed result and go to the Test tab, you will now see that the UnitTest1 was executed and that it is comppermiteed.

Unit Test 1

Continuous Integration – Inspection

Continuous Inspection is the process of an automated code rewatch of inspection conducted for your own code end up beingfore the behaveual checks are operate. There are subtle differences end up beingtween inspecting and checking smoothware. Testing is dynamic and executes the smoothware in order to check the functionality. Inspection analyzes the code based on a set of pcrimsonegoodd rules.

Inspectors (or static and dynamic analysis tools) are immediateed by identified standards that teams need to adhere to (usually coding or design metrics). Examples of inspection targets include coding “grammar” standards, architectural layering adherence, code duplication, and many kind of others.

Continuous Inspection crimsonuces the time end up beingtween a discovery and a fix. There are a numend up beingr of Continuous Inspection tools available. For this particular particular example, we are going to end up being using NCover 3.x which has an integration with TeamCity. Let’s see how we can carry away generally generally there Continuous Inspection and what it can do for us.

Download and Install NCover

NCover is a separate item which needs to end up being downloaded and installed. To Download NCover, plreare locatedve click on the folloearng link and download the 32-bit installer − /index.php?s=httpwwwncovercominfodownload.

32 Bit Installer

Run the downloaded installer and then click Next after the installer is started.

Next

Accept the License concurment and then click Next.

License Agreement

Accept the default components and click Next.

Custom Setup Default Components

Click on the Install button to end up beinggin the installation.

Install Button

Click the Finish button to comppermite the installation.

Finish Button

Launch the NCover installation for the 1st time by going to C:Program Files (x86)NCover NCover.Explorer.exe. You will simply need to install a trial key for the 1st time, which is a straightforward process.

Configure the Project in TeamCity to Use NCover

Step 1 − Go to your own project home screen and click Edit Configuration Settings.

Project Home Page

Step 2 − Go to Build Steps and click Edit for the TestStep. Continuous Inspection needs to operate along with the Unit checks which are degoodd.

Test Step

Step 3 − In the .Net Coverage section, click on .Net Coverage Tool. And then select the folloearng settings.

  • Choose the .Net Coverage tool as NCover(3.x)
  • Platform as x86
  • Version as v4.0
  • Path to NCover as C:Program Files (x86)NCover
  • Leave the other settings as they are

Step 4 − Click Save.

.net Coverage Section

Save

Step 5 − Now go to the main screen of your own project and click Run.

Main Screen Click Run

Tests comppermiteed

Step 6 − Once the make is operate, click on the Test comppermiteed. You will now see a Code Coverage screen and you will see many kind of metric indicators.

Code Coverage

Step 7 − You can now click the Code Coverage tab to get more information on the Code Analysis.

Code Analysis

Step 8 − Click the completecoveragereslot.html. You will now get a complete extensive reslot on the inspection carried away generally generally there for the .Net code.

Full Coverage Reslot Html

Continuous Integration – Database

Continuous Database Integration is the process of remakeing your own database and check data any kind of time a alter is appsitd to a project’s version manage repository.

In Database Integration, generally all the artifbehaves related to the database integration −

  • Should repart in a version manage system.
  • Can end up being checked for rigor and inspected for policy compliance.
  • Can end up being generated using your own make scripts.

Activilink ups that can end up being involved in Continuous Database Integration can end up being any kind of one of the folloearng −

Drop a Database − Drop the database and remove the bumociated data, so that you can make a brand brand new database with the exbehave same name

Create a brand brand new Database − Create a brand brand new database using Data Definition Language (DDL).

Insert the Initial Data − Insert any kind of preliminary data (e.g., lookup tables) that your own system is expected to contain when dereaspectcrimson.

Migrate Database and Data − Migrate the database schema and data on a periodic basis (if you are creating a system based on an existing database).

Modify Column Attributes − Modify table column attributes and constraints based on requirements and refbehaveoring.

Modify Test Data − Alter check data as needed for multiple environments.

So in our Continuous Database example, we are going to do the folloearng steps −

  • We will make a MS SQL Server database and a corresponding table.

  • We will make a script away generally generally there of SQL Server Management Studio. This database script will end up being used to set up our table in the database.

  • We will write a code in our ASP.Net project to access this particular particular database.

  • We will make a step in our project in TeamCity to operate this particular particular script.

  • We will check in our script into Git.

Steps to do this particular particular in the AWS database which was maked in an earsitr section.

Step 1 − Create an MS SQL Server database and a corresponding table. Let’s open up SQL Server Management Studio and make a easy database and table. Right-click databases and click on New Database.

New Database

Step 2 − Name it as Demodb and click OK

Demo DB

Step 3 − In the brand brand new database, proper-click and make a brand brand new table.

Tables Create New Table

Step 4 − You can add your own desicrimson columns to the table.

Add Desicrimson Columns

Step 5 − Save the table and name it as Demotb.

Step 6 − Now proper-click on the table and select the menu option Script Table as → Drop and Create to → File.

Menu Option

Step 7 − Save the file to the demo project folder as Sample.sql.

Save As Sample

This is what the database script would look like. It would 1st fall an existing table if present and then re-make the table.

USE [Demodb]
GO

/****** Object: Table [dbo].[Demotb] Script Date: 3/22/2016 7:03:25 AM

******

DROP TABLE [dbo].[Demotb]
GO

/****** Object: Table [dbo].[Demotb] Script Date: 3/22/2016 7:03:25 AM

******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Demotb](
   [TutorialName] [nvarchar](max) NULL,
   [TutorialID] [smallint] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

Step 8 − Now permit’s fastly alter our ASP.Net code to refer to the brand brand new database.

Step 9 − In the Tutorial.cs file in your own Demo project, add the folloearng collections of code. These collections of code will connect to your own database, conaspectr the Server version and store the version name in the Name variable. We can display this particular particular Name variable in our Demo.aspx.cs file through a Response.write command.

using System;
using System.Collections.Generic;
using System.Data.SqlCsitnt;
using System.Linq;
using System.Web;

namespace Simple {
   public clbum Tutorial {
      public String Name;
      
      public Tutorial() {
         string interinterconnectionString = "Data Source = WIN-50GP30FGO75;
         Initial Catalog = Demodb;
         Integrated Security = true;";
         
         using (SqlConnection interinterconnection = brand brand new SqlConnection()) {
            interinterconnection.ConnectionString = interinterconnectionString;
            interinterconnection.Open();
            Name = interinterconnection.ServerVersion;
            interinterconnection.Close();
         }
      }
   }
}

Step 10 − Add the folloearng code to the Demo.aspx.cs file to ensure that it displays the SQL Server version.

using System;
using System.Collections.Generic;
using System.Data.SqlCsitnt;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Simple {
   public partial clbum Demo : System.Web.UI.Page {
      Tutorial tp = brand brand new Tutorial();
      
      protected void Page_Load(object sender, EventArgs e){
         Response.Write(tp.Name);
      }
   }
}

Now if we operate the code, you will get the folloearng away generally generally thereput in the brangeser.

Output

Step 11 − Now permit us add our step in TeamCity which will invoke the database script. Go to your own project dashpanel and click Edit Configuration Settings.

Click Edit Configuration Settings

Step 12 − Go to Build Steps and click Add make step.

Add Build Step

Choose the folloearng options (Note that MS SQL Server csitnt need to end up being installed on the CI Server).

  • Runner kind need to end up being the Command Line.

  • Give an optional Step Name.

  • Run need to end up being Executable with parameters.

  • Command executable need to end up being C:Program FilesMicrosmooth SQL Server110ToolsBinnsqlcmd.exe

  • Command parameters need to end up being -S WIN-50GP30FGO75 -i Sample.sql. Where –S gives the name of the SQL Server instance.

Step 13 − Click Save.

Build Order

Now what needs to end up being ensucrimson is the make order. You have to ensure the make order is as follows.

Step 14 − You can alter the make order by choosing the option to reorder make steps.

  • The database setup need to end up being 1st – So this particular particular will end up being used to remake your own database from fresh.

  • Next is the make of your own application.

  • Finally your own check setup.

Test Setup

Step 15 − Now operate the git add and git commit command so that the Sample.sql file is checked into Git. This will trigger a make automatically. And this particular particular make need to comppermite.

Sample SQL

You now have a complete-fladvantaged make cycle with a continuous database integration aspect as well in your own cycle. In the next section, permit’s conaspectr this particular particular further and look at Continuous Deployment.

Now that you have done this particular particular with a local SQL Server, we can repeat the exbehave same steps for a AWS MS SQL Server which was maked in one of the earsitr sections. To connect to a Microsmooth SQL Server, you need to connect via the folloearng convention.

Step 16 − First see what is the name bumigned to your own database instance in AWS. When you log-in to the AWS, go to the RDS section under the database section.

RDS Section Under Database Section

Step 17 − Click on DB Instances in the next screen that comes up.

DB Instances in Next Screen

step 18 − Click on your own database and make a note of the endstage. In the folloearng screenshot, it is demodb.cypphcv1d87e.ap-saway generally generally thereheasternern-1.rds.amazonaws.com:1433

Endstage

Step 19 − Now to connect to the database from SQL Server Management Studio, you need to specify the interinterconnection as demodb.cypphcv1d87e.ap-saway generally generally thereheasternern-1.rds.amazonaws.com,1433 (Note the comma used end up beingtween instance name and slot no).

Connect to Server

The folloearng screenshot shows a successful interinterconnection to the database.

Successful Connection

Then you can repeat all the exbehave same steps. The Sqlcmd command will end up being as follows −

Sql cmd Command

This exbehave same command can end up being replaced in the Database make step in TeamCity. When you execute the sqlcmd command, the table will end up being maked automatically in your own SQL Server database in AWS.

Database Build Step

Continuous Integration – Deployment

Automated makes and repeatable makes. Automated checks and repeatable checks. Test categories and check frequencies. Continuous inspections. Continuous database integration. These string of tasks in creating an effective CI environment primarily enables one key end up beingnefit: releasing worruler smoothware at any kind of stage in time, in any kind of environment.

In our previous chapters, we have accomplished all of the folloearng segments −

  • Created our code.
  • Ensucrimson a proper make in TeamCity.
  • Created a Database Integration process.
  • Conducted successful checking.

Now the only slimg remaining is to carry away generally generally there an automated deployment, so that our entire process is comppermite.

For an automated deployment in our case, we need to follow these steps −

  • In our deployment server, ensure that IIS is wislimstalled.

  • Ensure that IIS user is given access to our database.

  • Create a publish profile which will end up being used to publish the site when it is built.

  • Ensure we alter our MSBuild command to do an automatic deployment.

  • Automate TeamCity to do an automatic publish.

  • Do a git commit to ensure all your own files are in Git.

Step 1 − Configure a local IIS Server. If you have a local or remote IIS Server, the folloearng configuration can end up being carried away generally generally there to deploy our application. It’s always a great prbehaveice to see if a deployment can end up being done manually end up beingfore it is done in an automated fashion.

Step 2 − On a Windows 2012 server, go to your own Server Manager and click on Add Roles and Features.

Server Manager

Step 3 − Click Next on the folloearng screen that comes up.

Add Roles and Features Wizard

Step 4 − Choose roles-based or feature-based installation on the next screen and click Next.

Installation Type

Step 5 − Select the default server and click Next.

Default Server

Step 6 − Choose the Web server role and click Next.

Web Server Role

Step 7 − In the next screen that comes up, click Next.

Click Next

Step 8 − Click Next again on the folloearng screen that appears.

Web Server Role Click Next

Step 9 − In the next screen that pops up, click Next.

Role Services

Step 10 − In the final screen, you can click the Install button to install the IIS.

Install IIS

Once you have IIS installed, you can open up it by open uping the Internet Information Services.

Internet Information Services

Step 11 − Click Application Pools, you will see a pool with the name of DefaultAppPool. This needs to have access to SQL Server in the next step.

Step 12 − If we need to connect a ASP.Net application to a MS SQL Server application, we have to give access to the default application pool to the SQL Server instance, so that it can connect to our Demodb database.

Step 13 − Open SQL Server Management Studio. Go to Logins, proper-click and select the menu option New Login.

New Login

In the next screen, update the folloearng parameters and click OK.

  • Login name as IIS APPPOOLDefaultAppPool.
  • Default database – This need to end up being our database, which is demodb.

Parameters

Step 14 − Creating a Publish Profile. The publish profile is used in Visual Studio to make a deployment package that can then end up being used with MS Build and in any kind of CI Server accordingly. To do this particular particular, from Visual Studio, proper-click on the project and click the menu option of Publish

Publish Profile

Step 15 − In the next screen that comes up, select to make a brand brand new Publish profile, give it a name – DemoDeployment. Then click the Next button.

Demo Deployment

In the ensuing screen that shows up, add the folloearng values −

  • Choose the Publish method as Web Deploy.
  • Enter the server as localhost.
  • Enter the site name as Default Web Site/Demo.
  • Put the destination url as http://localhost/Demo

Then click the Next button.

Publish Web Next Button

Step 16 − In the next screen, click Next.

Publish Web Configuration

Step 17 − In the final screen that comes up, click the Publish button.

Final Screen

Now if you go to the C:DemoSimpleProperlink upsPublishProfiles location of your own project, you will see a brand brand new publish profile xml file maked. This publish profile file will have all the details requicrimson to publish your own application to the local IIS server.

Step 18 − Now permit’s customise our MSBuild command and use the above publish profile and see what happens. In our MSBuild command, we specify the folloearng parameters −

  • Deploy on Build is true – this particular particular will trigger an automatic deployment once a successful make is done.

  • We are then mentioning to use the Publish profile which was used in the above step.

  • The Visual Studio version is simply to end up being mentioned to the MSBuild deployment capcapability on what is the version of the Visual Studio end up beinging used.

Visual Studio Version

When you operate the above command, MSBuild will trigger a make and deployment process. What you will note that, it is deploying it to our Default Website in our IIS Server.

Default Website

Now if we brangese to the site – http://localhost/Demo/Demo.aspx we will see the folloearng away generally generally thereput, which means that the MSBuild did a successful deployment to our website.

Localhost

Step 19 − Automating through TeamCity – Now it is time to add a task to our TeamCity server to automatically use MSBuild to deploy our application, based on the above mentioned steps.

Step 20 − Go to your own project dashpanel and click Edit Configuration Settings.

Project Dashpanel Configuration Settings

Step 21 − Go to Build Steps and click Add a Build step.

Build Steps Add Build Steps

Choose the folloearng options −

  • The operatener kind need to end up being MSBuild

  • Give an optional Step name

  • Enter the make rawaye as Simple/Simple.csproj

  • Keep the MSBuild version as Microsmooth Build Tools 2013

  • Keep the MSBuild Toolsversion as 12.0

  • Put the command collection as /p:DeployOnBuild = true /p:PublishProfile = DemoDeployement /p:VisualStudioVersion = 12.0

Step 22 − Click Save.

Build Configuration Settings Click Save

MS Build Version

Make sure that in the make steps, the Deploy step is the final step in the chain.

Deploy Step

Step 23 − Now permit’s do a final git commit, to ensure all the files are in Git and can end up being used by TeamCity.

Final Git Command

Congratulations, you have successcompletey set up a comppermite Continuous Integration Cycle for your own application, which can end up being operate at any kind of stage in time.

Continuous Integration – Best Prbehaveices

Let’s have a final rewatch of the end up beingst prbehaveices of Continuous Integration based on all the lessons we have understandt so far −

  • Maintain a code repository − This is the the majority of basic step. In all our examples, everyslimg is maintained in a Git repository proper from the code base to the Publish profiles, to the database scripts. It must always end up being ensucrimson that everyslimg is kept in the code repository.

  • Automate the make − We have seen how to use MSBuild to automate a make along with using a publish profile. This is again a key step in the continuous Integration process.

  • Make the make self-checking − Ensure that you can check the make by maintaining device check cases in place and these check cases need to end up being in such a way that it can end up being operate by the Continuous Integration server.

  • Everyone commit is to the basecollection every day − This is a key principle of Continuous Integration. There is no stage staying till the end of the entire process to see who breaks the make.

  • Every commit (to basecollection) need to end up being built − Every commit made to the application, needs to end up being successcompletey built. If the make fails for whatever reason, then the code needs to end up being alterd to ensure the make comppermitees.

  • Keep the make fast − If the make is sluggish, then it would indicate a issue in the entire Continuous Integration process. Ensure that the makes are always limited to a duration, preferably need to never go end up beingyond 10 moments.

  • Everyone can see the results of the lacheck make − The TeamCity dashpanel gives everyone a watch of all the makes, which have possibly comppermiteed or failed. This gives a great insight to all the people who are involved in the Continuous Integration process.

NO COMMENTS

LEAVE A REPLY