Continuous integration and Continuous delivery using VSTS
In this article I will explain how I setup basic CI/CD pipeline in VSTS.
Creating build agent
First thing is to go to your VSTS (it is called Azure DevOps now) and download build agent. Build agent is not only available here, you can freely find it Microsoft pages, so if for any reason downloaded build agent is giving you trouble you can download newer version. Built agent is basically piece of sotware that will do actual build. In larger systems you ofter have server that is dedicated to build your sofware (“build servers”). If your CI/CD pipeline has lot of build definitions (I will take about them later), lot of projects, and large projects that take long to build, and you also have team with lot of developers, build agent will work hard which means that will use lot of physical resources of machine.

Every build agent has some capatilibilities. For example, you can see computer name it runs on, installed MSBuild version on machine it runs on, java version and node.js version if it has installed. Later, you can assign which build agent (if you have more of them) will run some built definition using this capatilibilities.

To install download zip file, then extract that zip where you want your build agent to live. For example, I extracted it to C:\agent-test\agent folder. After that open command prompt or Powershell as administrator and point location to that folder and run command C:\agent-test\agent> .\config.cmd. First thing is to enter server URL. It is place where your code, and your VSTS live, for example http://git.mycompany.com, After that you are asked for authentication type. In my case I had to choose Integrated because I connect to VSTS using my computer credentials. In your case, your type of authentication could be PAT (personal access token) and you should enter “PAT”,and when asked enter your PAT. You can obtain you personal access token by going to your profile in VSTS and choosing “Security”.

After that you are asked to enter agent pool (I just pressed enter for “default”), then you are asked for agent name (I called it FTPIISagentD) and for work folder (I pressed enter for default “_work” folder. (Inside C://test-agent/agent folder I created priviously). Last thing you are asked is do you wont to run agent as service (I decided not to accept default setting, and enter “Y” because I want it to run as service. Once your service is successfully installed you can confirm in your VSTS it is installed.
Creating build definition
I didn’t bother using built in templates when started creating new build defintion in VSTS so I started with empty. Built-in Visual Studio template was generating to many errors so I decided to start from scratch. First thing is to select project and then in Build&Release tab select “New”. In presented wizard it is necessary to select repository and default branch from which code will be built. Depending on your braching strategy that could be your master or relase branch. In wizard there is only possibility to enable Continious integration by enabling checkbox. It is possible to enable, or disable it once built definition is created by going on “Triggers” option of selected built definition. Continious integration means that each time code is checked in repository build will be triggered. It is also possible to schedule build, so for example you can build and then release application every night. In “General” tab, there is possibility to change some general settings but thing that was most intereseting to me is Demands section. Because I had multiple build agents on different machine I had to target specific build agent. This is possible by adding new demand in “demands” section. It is possible to add new demand with name “Agent.Name” and value “FTPIISagentD” (or whatever you called your build agent).
Most important thing is ofcourse to define build steps. To make build possible it is necessary that maching your build agent is run on has build tools installed. Also .NET framework that your project uses also has to be installed on build machine. Almost every thing your development machine requires to sucessfully install your project build machine also has to have. Although it is not necessary to install Visual Studio IDE to make build, this was easiest to me. I checked all required components (most important thing is to pay attention if you have selected Build Tools, .NET framework – those are keywords you are looking for that need to be installed. I checked “ASP.NET and web development” option inside Visual Studio Installer. If you are using .NET Core you will ofcourse select that option.
First build step I added was Nuget install build step. You can add new build step by clicking “Add build step”. Once you click there you, task catalog opens with lot of predefined tasks that are most common. There is Extract Files task, Copy File, FTP uplaod, Gulp and Grunt tasks, MS Build task and much more. If you find what are you looking for you can search on marketplace or even make you own task and share it on marketplace.
To be continued at seconf part of this article.