.Net Core and TypeScript Continuous Integration Testing with Jenkins on Linux

Georg Dangl by Georg Dangl in Continuous Integration Monday, May 29, 2017

Monday, May 29, 2017

.Net Core and TypeScript Continuous Integration Testing with Jenkins on Linux
Posted in DotNet Angular Jenkins

I've previously blogged about the NetCoreHeroes project, an Asp.Net Core demo app that features an Angular frontend. It's been my learning project for getting a nice WebDev experience in Visual Studio and Jenkins, and recently there's been interest in getting it to work in Linux.

Being a traditional Windows and .Net guy, I've never done a lot with Linux, but I wanted to see how easy it actually is. It actually is pretty easy and took me only two evenings of getting everything up and running on Linux. I've used a Hyper-V virtual machine with Ubuntu Server 16.04, but results should be comparable across distributions.

Install Hyper-V

On a Windows host system, you've got to install the Hyper-V role. I'm running it on an Intel NUC with an Atom processor. It sits somewhere behind the TV in the living room, is ridiculously slow, but gets the job done and costs about 300,- €.

Windows Server 2012 R2 - Install Hyper-V Role

From the Server Manager, go to Add Roles & Features, select the Hyper-V role, confirm the GUI and PowerShell management tools and click on next until you’re in the configuration tab for Virtual Switches. Since the VM will need internet access, you’ll want to select a network interface through which you’ll connect the virtual machines to the outside world.

Hyper-V Virtual Switch Configuration

In an ideal world, your virtualization host has multiple LAN ports, with a dedicated one for the virtual machines. However, the NUC behind the TV doesn't have that, so we’ll accept the risk and move on. This is mostly a problem for connectivity, since misconfiguration might make your machine unavailable.
You don’t need to add support for Live Migrations for this example and can go with the default storage locations for VM configuration and hard disks.

Setup the Virtual Machine

Download Ubuntu Server

Go to https://www.ubuntu.com/download/server and download the current Long Term Support (LTS) version of Ubuntu Server. At the time of writing, that’s 16.04.2.

Provision the VM

In the Hyper-V manager, create a new virtual machine. I've assigned it 2GB of RAM and a 20GB Hard Disk, this should be plenty for a simple Jenkins instance and one Asp.Net Core demo site. Generation 2 VM have the newer features with the drawback of not being compatible with any hosts pre Windows Server 2012.

Provision a Virtual Machine in Hyper-V

Install Ubuntu Server & Jenkins

When provisioning the VM, I’ve selected to install an operating system from an image and chose the *.iso that was downloaded earlier for Ubuntu Server. After the VM has been provisioned, you need to change its firmware settings to deactivate Secure Boot since that’s not compatible with Ubuntu Server. After that, simply connect to it and power it on.

Ubuntu Server Installation Welcome Screen

This tutorial doesn't cover how to install & setup Ubuntu Server itself. The setup is quite self explanatory (which I would not have expected from Linux if you had asked me a week ago).

For the Jenkins installation, DigitalOcean has a great tutorial that you should follow. However, I configured the firewall to only allow incoming traffic to Jenkins for my private home networks IP range: sudo ufw allow from 192.168.1.0/24 to any port 8080. In case your firewall is disabled in Ubuntu (ufw status returning inactive), run sudo ufw enable to activate the firewall. After the initial setup, Jenkins is running in your Linux VM:

Jenkins Welcome Screen on Ubuntu Server

Install Development Environment & Tools

On the build server, you’ll need dotnet and npm available.

First, follow the official Microsoft .Net Core Linux installation instructions to enable dotnet support. To install npm, run these commands:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

Jenkins Plugins

This one is easy. There’s already support for jUnit test results in Jenkins, meaning the TypeScript tests are already supported. For the xUnit based dotnet tests, install the xUnit plugin in Jenkins and you’re good to go.

Configure Jenkins

The NetCoreHeroes project has both .Net and Angular unit tests that are going to be run in Jenkins.

The project's SCM git repository is located at https://github.com/GeorgDangl/NetCoreHeroes/. You can take a look at the project to get a starting point for your own CI builds. For Linux, I've had to deviate a bit from my standard configuration. The awesome Chutzpah JavaScript test runner is only available for Windows, so I had to switch to Karma for the Linux environment. I get that the Karma runner is actually much more used, but it doesn't integrate as seamlessly in Visual Studio. In the NetCoreHeroes posts series, I've described the complete way from setting up the project to a fully automated testing and deployment scenario with Windows.

Back to Linux, here's the Jenkins build configuration:

NetCoreHeroes Jenkins Build Configuration for Linux

And the post build actions to publish the test results:

Jenkins Post Build Actions for NetCoreHeroes with Angular and Asp.Net Core on Linux

Save the config, click on Build Now and take a look at what your unit tests have to tell you:

HeroService.HeroService getHeroes should have expected fake heroes (from PhantomJS 2.1.1 (Linux 0.0.0))

.Net Core and Linux really IS easy!

Happy platform-independant testing!


Share this post


comments powered by Disqus

About me

Hi, my name's George! I love coding and blogging about it. I focus on all things around .Net, Web Development and DevOps.

DanglIT

Need a consultant for BIM, GAEB or Software Development?

Contact me at [email protected], +49 (173) 56 45 689 or visit my professional page!

Dangl.Blog();
// Just 💗 Coding

Social Links