In this series, I will guide you to create a complete CI (build) pipeline in Azure DevOps, covering all necessary aspects to build a full net core application (an API service), and deploying to docker hub.
The aspects covered in this series are:
- Get source code from GitHub
- Code Analysis
- Unit Tests
- Unit Tests coverage
- Build DockerFile
- Push DockerFile to DockerHub
- Publish artifacts for CD pipeline
Looking at the steps above, it looks simple to achieve, but while I was creating the pipeline, I´ve face some challenges to resolve to fully attend all aspects above.
This series are divided in 4 topics:
- The code and Build Pipeline
- The code analysis and unit tests steps
- Building and publishing your Docker image
- Final steps and summary
Part 1 – Code and Build Pipeline
In this part I will show how to create a simple repository and a simple web api application in net core using swagger
I use Github as repository for this demo, but you can use AzureDevops Repo or even Bit Bucket as well.
Get the code repo here, you can use it in the following steps:
The code consist in two projects, a web api application and a test project. The web api contains basic functionalities using the concepts of DI (Dependency Injection). The test project mocks the dependency and test it to produce the % of code coverage of your application.
To create your build pipeline, access your Azure Devops subscription (https://dev.azure.com/), create a project (in my case net-core-svc-devops-sample) and access the build pipelines list (https://dev.azure.com//net-core-svc-devops-sample/_build). Create a new pipeline by clicking the New pipeline button.
A new page will ask to select your code repository, you can use the Azure Repos Git, GitHub, Subversion, Bitbucket or another git version control. I will use the example GitHub repository (https://github.com/aledaccas/net-core-svc-devops-sample). Click Continue
In template page, select empty template and apply. The result will be a empty pipeline with one agent job. Change the pipeline agent pool to Hosted Ubuntu 1604. This will be necessary to build the docker image in linux version.
Press Ctrl+s to save your pipeline. Now you are ready to add the tasks to test, analyze and build your net core container image. Check next post for unit test and quality control.