This article originally appeared on my personal blog.
Give the most tedioust jobs to your laziest employee and they will automate it. My boss
That's right. I am lazy. I hate repetitive tasks. And as a developer you probably feel the same way.
One of those repetitive tasks is deployment
There are numerous ways and frameworks to set up automated builds and deployments. Some of them can do just about anything almost up to the point where they will make you coffee while you wait for your builds.
Recently while working on a small ASP.NET Core website I found out that Microsoft Azure has a very simple deployment tool for building and deploying from your favourite code repository to an Azure web application. I was especially happy to find that it supports BitBucket even though it seems anything not-on-Github is not cool.
Well, I am too old to be cool and I like Bitbucket so bear with me.
Setup
Setup is a breeze. Got to the new Azure portal and create your new web application.
After the web app has been created, go to your web app and choose "Deployment Options".
The next steps allow you to log in to your source code provider (i.e. Bitbucket) and choose project and branch (typically the master branch). The beauty here is that Azure supports pulling code from all kinds of sources like Dropbox, Onedrive, Github, and of course Bitbucket.
After you save your settings, Azure will fetch your last commit and start building it. You can se the progress by clicking "Deployment options" again.
Build Errors?
It looks like Microsoft has just recently upgraded the compiler but I have previously run into problems with building newer C# features such as inline declaration of variables like so.
var salaries = new Dictionary<string, decimal>()
{
{ "Jakob", 10000000000 },
{ "Some other guy", 42 },
};
// Inlining variable declaration
if (salaries.TryGetValue("Jakob", out var salary))
{
// Do something with salary.
}
If you run into this problem, all you need to do is add the Nuget package Microsoft.Net.Compilers to your project. This will make sure that your project is compiled with the latest C# compiler.
Conclusion
This kind of deployment is extremely simple and easy, which is a good thing. On the other hand it will not run any unit tests in your project and it will deploy straight to production without any testing or staging. You might consider this solution for smaller, non-mission-critical sites.
Top comments (5)
.net core has a very nice support from visual studio team services. You can build your app there, give it a version number or some similar things. Even run a database migration if you want to.
It is really worth considering for small team (up to 5 devs, it is free), it provides a source code repository, CI/CD support and very well cooperate wirh azure.
I wasn't aware of solution which you presented, it is also nice and really straight forward to configure and understand. Thanks for sharing!
Hi Pawel,
Yes, VSTS is a great product but it is also huge. Do you use VSTS with Git or with classic TFS?
Thanks for reading.
We are using VSTS as a VCS also (so with TFS), on CI it is pulling code from local feeds. It is really comfortable, when you do not have to configure git connections.
Good article but I think you're underestimating what you can do with this.
Firstly you can include staging / test deployments just by a tweak to your git branching strategy. IE merge into master branch to deploy to test / staging and merge into release branch to deploy to production.
Also you can run unit tests on your deployment with just a couple of tweaks to the default deployment as described here
Different branches? Yes, of course. Good thinking.
I am not familiar with Kudu so thank you for the link.