I have previously written about how to create nuget package .net core and in that post I discussed using a service such as Appveyor as the CI/CD service. Which is what I originally started using when I developed my Threenine.Data and Threenine.Map projects at the time.
However, as things have progressed with Denizon and Threenine.co.uk and our Software Development projects became bigger we decided to invest in building our own Continuous Integration and Continuous Deployment infrastructure.
We’ve been using Jetbrains products for years especially PHPStorm, WebStorm and Rider as our primary Integrated Development Environments (IDE) and regular readers of my blog will know I always speak very highly of their products. So it probably would come as no surprise that we decided to make use of JetBrains TeamCity as our primary CI/CD server.
I recently released an update to my Threenine.Data nuget package and in the process configured the Build and Release pipeline to make use of TeamCity. I previously mentioned this in the Continuous Integration Check-in Dance , wherein I discussed the process developers typically follow when commit code to their version control repository and initiating the CI/CD pipeline.
In the post, I discussed making use of the same build script on your developers workstation as you would use on the build server. The build script in question I use in my project is Cake – A Cross-platform build automation system with a C# DSL for tasks such as compiling code, copying files and folders, running unit tests, compressing files and building NuGet packages.
I have previously discussed how to create a nuget package with.net core, I thought I would further elaborate on how I make use of the same Cake.build file in my project on the build server.
Team City Build Configuration
A team city A Build Configuration is a “type of build” – a combination of settings edited in the UI which are used to start a build and group the sequence of the builds in the UI. The settings include Version Control System (VCS) settings (from where to checkout sources for the build), what build procedure to run (build steps and environment parameters), triggers (when to start a new build) and others.
I have configured my General settings for my build as follows. There is nothing really complicated here and basically its just adding details regarding my build and the product.
As you can tell, I am using Github and git as my VCS for this project. I have also configured my project to make use of the GitFlow branching and merging strategy, which is a good branching merging strategy to follow and essentially creates 5 types of branches in your Git repository. Master, Develop, Feature, Hotfix , Release and Support.
In my project, at this stage I only currently foresee that I will actually only be using 4 of these branches to perform builds on. i.e. Master, Develop, Feature and hotfix. The master branch I will be using as the Release branch.
Therefore builds will be able to be initiated and performed on all branches, but only code that is merged into Master branch will be deployed after a successful build
I have also defined 3 build steps.
We will make us of the cake.build file in this step and despite we could also most use Cake to Package our Nuget File and more than likely publish it using cake too. I have chosen to do this steps within TeamCity for a couple of very good reasons.
The primary reason why I like to use TeamCity for this purpose, is that they I can make use of TeamCity to act a local Nuget server in my development environment which means I can make use of Development and Pre-release versions of my nuget packages without having to deploy them to Nuget.
Actually configuring TeamCity to make use of the Cake build script is a fairly trivial process and I have to do is make use of the Command Line runner task and provide the name of the script I want team city to run. In this instance it will be the
build.sh , that we generated using Cake bootstrapper.
The third and final step of our build process is that we will deploy our nuget packages to Nuget.org but only when we merge from Develop into master. We will use the TeamCity nuget publish for this task.
The two important aspects of this step is that we add a condition on the execute step to ensure that the step only executes if we are building on the master branch.
We also only publish packages that have been dropped into the build folder.
The final setting we need to make in our CI/CD process, is when exactly the process is executed. I want this process to be kicked whenever the a commit is made to the repository. So we will add a VSC trigger to our build.
You’ll notice I have not included a branch filter, because I want the build to executed on every branch that is committed.
We have now completed a basic build and deploy pipeline in TeamCity.
With all this in place, we can now just continue to develop our Nuget package, once our development has completed and we have finished with the Continuous Integration Check-in dance and we commit to our Central code repository the build will kick off.
- How to use Github actions to build & deploy Github nuget packages - October 14, 2021
- How to implement cross cutting concerns with MediatR Pipeline Behaviours - October 5, 2021
- Understanding the difference between Queue and Stack Data Structure - September 22, 2021