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.
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,- €.
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.
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.
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.
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:
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
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.
The NetCoreHeroes project has both .Net and Angular unit tests that are going to be run in Jenkins.
Back to Linux, here's the Jenkins build configuration:
And the post build actions to publish the test results:
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!