< Previous Challenge - Home - Next Challenge >
Great we now have some infrastructure and some code, lets build it. In DevOps we automate this process using something called Continuous Integration. Take a moment to review the article below to gain a better understanding of what CI is.
In Azure DevOps we use Azure Pipelines to automate our build process. For our application the build process will not only compile our .NET Core application, it should test it, and package it into a Docker Container and publish the container to Azure Container Registry.
- Use the classic editor to create a build pipeline using the ASP.NET Core template (the one with the icon with the black box) and name it
CI Build
- Enable continuous integration on your build pipeline (hint)
- Review the 4 .NET Core build tasks that were added to our build pipeline by default. These are the 4 major steps to building a .NET Core application (Hint).
- First we call the
restore
command, this will get all the dependencies that our .net core application needs to compile - Next we call the
build
command, this will actually compile our code - Next we call the
test
command, this will execute all our unit tests - The last .NET Core build task in the template is to
publish
the .net core app. The template publishes the application to a zip file, we don’t want it zipped so undo this setting. Additionally, change the output argument to here$(System.DefaultWorkingDirectory)/PublishedWebApp
- First we call the
- You can delete the
publish artifact
step since we are going to create a container and publish it to Azure Container Registry. - Now that our .NET core application is compiled and all the unit tests have been run, we need to package it into a Docker Container and publish the container to Azure Container Registry, to do this we are going to add a docker task to our build pipeline.
- We want to use the
buildAndPush
command with the following Docker file**/Dockerfile
, build context$(System.DefaultWorkingDirectory)/PublishedWebApp
and tag$(Build.BuildId)
(NOTE: here we are dynamically pulling the build number from Azure DevOps at run time) - Next we need to connect it to the container registry and repository (i.e.
<prefix>devopsimage
) that we setup in our infrastructure as code challenge.
- We want to use the
- Lets kick off a build manually to ensure that we have a working build.
- Next lets notify the team if the build breaks by setting a Build Option to create a new Work Item.
- Now, make and check in a code change that will break the build. Ensure that a work item gets created.
- Referencing the work item that was automatically created, fix your code, ensure the build looks good, and then resolve the work item that was created.
- Your build should complete without any errors.
- Review the test results generated by your build. HINT: look in the logs from your build to find where the test run was published.
- Using the Azure Portal or CLI you should see your container in your Azure Container Registry Repository