Author: paulthecyclist

Continuous Integration and Delivery with Visual Studio Team Services (Part 2)

This post follows on from part 1, where I walked through the creation of the CI part of our pipeline,  creating a Visual Studio Team Services build definition that was triggered by a checkin to our GIT repository. This the CD part.

The goal is to deploy automatically after build our .Net MVC website.

I’m going to start, in Visual Studio Team services, going into my project Binet and clicking on the releases tab. As we have no releases yet, it should look a bit like:

step2_1

Let’s create a new release definition – we now see the following dialogue.

step2_2

We just want a basic deploy of our code to an Azure website for this demo. Azure App Service Deployment is good for us. The other Azure App Service deployments are fun too, but maybe another time. Hit Next and now we’re creating a release definition. This is based on our build from earlier (unimaginatively called standard build). Choose this Standard build and check the continuous deployment box – that’s the whole point of this!

step2_3

Next it will take you to the environments tab. A complicated looking tab to choose a source and destination is how I like to think of it. Here we need to pick our subscription, and the name of the app service we want to deploy to, we’ll call it binet.

step2_4

 
As this is was my first time I also needed to hit authorise, when choosing my subscription; I don’t pretend to understand the consequences of this, other than you gotta do it.

step2_5

We also need to setup our source. This is the Package or folder part. By clicking the ellipsis we can select the (_PublishedWebsite) folder that was output in step 1 of the process and select the folder immediately under this, where our website files exist.

step2_6

The path that we’ll end up selecting is:
$(System.DefaultWorkingDirectory)/Standard Build/drop/_PublishedWebsites/NextFib

Hit save and our release definition is complete. Let’s force it to run manually to test if we did it right or not; choose create a release from the Release tab that’s against the release definition.

step2_7

This will bring up another dialogue, where you can pick a particular build to deploy. By default it’s displaying the latest build (number) available – this is the one we want. So accept these defaults and hit create.

step2_8

Much like the creating of a build, your request will be queued up and picked up as soon as an agent is ready. For me, a mere few seconds later and an agent picked up my request and the deployment build began.

step2_9

After a couple of mins it finished and… it failed. If things worked first time, how could you learn? Helpfully? I also received an email telling me about what a failure I am.

step2_10

Big plus here, is a very clear error message (way better than msbuild exited with code 1). It turns out you need to create an instance of the App Service in the subscription you picked in order to deploy to it. Doh! An easy problem to fix though. I hopped over to my Azure Portal and create an empty App Service entry named binet

step2_11

Let’s try that deploy again. Going back to visual studio team services, navigate to releases and kick one off again. This time…

step2_12

 

Yes – deployment was successful!
My website showcasing Binet’s forumla is now live and being hosted in Azure. Go check it out.

step2_n

 

After this I performed a couple of minor updates to the site, checked them into Github and verified that the CI worked and the CD deployed to the Azure App Services website. I appreciate this is a very simple example, but is one that can be built on. What I do like about this solution is having my entire infrastructure in the cloud; also it’s cost me nothing!

Advertisements

Continuous Integration and Delivery with Visual Studio Team Services (Part 1)

How easy it is to use TFS online (aka Visual Studio Team Services) to build, run unit tests and deploy a simple.Net MVC website into Azure websites? This post is part 1 – building, running tests and creating the artifacts. Part 2 will look at using MS Release Management (part of VSTS too) to take the build output and deploy it to Azure websites. The goal is that when I check in my code, Visual Studio Team Services will compile it, test it and then deploy.

Recently I used the Visual Studio Team Services tooling to achieve CI and CD, and to my surprise it was quick and actually, reasonably pain free to setup. I was so pleased, I thought I’d write a couple of blog posts about it.

I created a simple .Net solution, that consisted of 3 projects.

  1. MVC Website
  2. Test Project
  3. Class Library

The website is a simple implementation of Binet’s formula to calculate the nth item in the Fibonacci sequence. Not important right now and I’ll go into the website side of things more in a subsequent post. I hooked it into a github repository, got it working and committed it.

Now the interesting part begins, of getting Visual Studio Online Visual Studio Team Services to create the build.

Step 1 – Go to Visual Studio Team Services, sign in/create a free account and create a new project, calling it Binet, selecting GIT as the source control.

step1

 

 

Hit Create. Next we need to connect it to our GIT repsoitory.  As our code is already hosted at GitHub, choose setup build.

step2

Next – we’re creating a build definition, online. Exciting times. From the options available we want to use the Visual Studio template.

step3

Hit Next. Now we need to connect the build definition to our github repository. All other defaults remain.

step4

 

For me, this popped out a new tab asking me to connect my VS online account to my GitHub account.

step5
Small gotcha for me – hitting the authorize button tried to create a popup that chrome blocked, so had to allow this popup).

Allow VS Online access to my github account

step6

I then selected my Binet respository, came back to VS Online and hit save, and we’re done! We have a complete build definition using virtually all the default settings.

Well, not quite. It won’t create the website in the artifacts folder. What the duce…
Yes, the most important part of building a website, is, well the website! By default it was creating just the test and class library project.

There is a solution though. This blog, details it.
The gist is we need to get msbuild to create the infamous _PublishedWebsites  folder, which contains all the files the website needs. This is achieved by passing these magic commands to msbuild:

/p:OutDir=$(build.stagingDirectory) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true

Navigate to the build definition, and change the msbuild arguments passed into the ‘Build Solution step.

step7

We want to make sure we publish all files to the artifacts directory, so we need to make a small change to the Copy files step. This is changing the contents to **\*

step8

Nearly there. As we have a moved the output slightly, we need to update the test step to be able to locate the test assemblies now. That involves changing the entry for test assembly from

**\$(BuildConfiguration)\*test*.dll;-:**\obj\**

to:

$(Build.StagingDirectory)\*test*.dll;-:**\obj\**

Which looks like this

step9

Now we are ready to try it. Hit the Queue new build button. I just accepted the default options and hit ok.

step10

and we’re off and waiting for a build agent. For me this didn’t take very long at all.

step11

Then the build starts

step12

…and succeeds!

 

step13

We can also look at the stats of the build, in the build summary. From here you can also view the artifacts to verify what was built.

step14

We now have an active build definition set up in Visual Studio team services. Every time a checkin is detected on our Github repository a new build is triggered.

In my next post I’ll show how to setup continuous delivery to Azure websites using the online Release Management tooling.

MY NDC London Highlights

A couple of weeks ago, I was delighted to be able to attend NDC London, and be part of the crew.

Below is a brief commentary on some of the talks I attended. The NDC crew are uploading videos all the time, I’ll try and update this page with links to the videos when they become available. You can watch the videos here

Scott Hanselman delivered a typically polished and amusing keynote, the gist being that we’re finally starting to deliver web applications instead of delivering applications inside web pages. Scott’s keynote can be found here.


tbl_hanselman

“…none of us can ever have a title higher than web developer”

Good point, if Tim’s just a web developer, are you really a senior web developer? More to come from Scott Hanselman, Principal Program Manager at Microsoft.

The theme of delivering content, without fighting the Web carried on.

20160114_162912

Dylan Beatie

Dylan Beattie built on this, with his, the rest of REST talk. Take away for me was, you should be using Hypertext in your RESTful APIs. Dylan introduced us to Hypertext Application Language (HAL).

20160115_102200

Ali Kheyrollahi

Interestingly, Ali Kheyrollahi, in his talk 5 Anti-Patterns in designing APIs, also touched on Hypertext; His solution was a little different, preferring to use HATEOAS.

David Neal presented a lovely introduction to Node.js. Certainly presented a case that you can build really good apps with this. Cited nice example of how the new Visual Studio Code editor is built on top of Github’s Electron, which is, you guessed it, based on Node.js.

20160113_181227

Peter Meyers

Peter Meyers delivered a great talk, building a demo from scratch, showcasing how you can use Azure’s Machine Learning, to use a basic neural network to predict data. A very hands on demo, a lot of complex content covered and explained beautifully. Brought back happy memories of my student days studying AI.

20160113_102159

Kevlin Henney

My favourite talk, was delivered by Kevlin Henney, SOLID deconstruction. A measured and thoughtful look at the SOLID principles, where they come from and what they really mean. I liked it, as it encouraged you to think. Enough that I already have a couple of blog posts in mind on the back of it.

20160113_151357

Doc Norton

Doc Norton gave a good talk too, the building blocks of knowledge culture. To me it seemed like a look into the future of how great (software) companies will be. Takeaway for me was, the idea of having fluid teams, let people choose the team they want to work in. It works.

20160115_122656

Dan North

Dan North also gave a thought provoking talk, with a new take on how to structure your agile department. Not sure it’s what he wanted the audience to take away but he talked about what an hypothesis is (a falsifiable statement, he concisely stated). It’s also something to be built upon, as you learn more. Agile methods should and need to be improved all the time, his talk introduced us to some new ideas that worked for him when it comes to scaling agile (you can’t scale agile!).

20160115_140843

Scott Hanselman

I saw that Hanselman fellow again on Friday, tooting the wonders of Azure.

Microsoft wants your for loops.

He happily chimed. On a personal note it also wants you to set the service level for your app services incorrectly too, in it’s ever confusing portal (cost me over £50 for that mistake). He is a very accomplished speaker too, pleasure to be entertained by him.

Talking of entertainers, king for me was Troy Hunt. So entertaining! Nice guy too, as his crew, I had a nice chat and handshake before the show, Making Hacking Child’s Play. Best bit – the HarlemShake, works on far too many sites and it’s soooo fun!

And finally I saw John Skeet, live, 3 times. No words can convey how deep and impressive his C# and OO knowledge is.