Working with both Azure and Azure DevOps is always fun, and the possibilities of automation are endless. I have written many articles on these topics and you can read them here. As you all know that the .net6 is been a talk in the market and I can’t wait to try out things there. Here in this post, we will see how to use the Azure DevOps pipeline to build, restore and deploy the .net6 application to Azure Web App Service. Let’s get started.
At this point, I will assume that you have a .net6 application, Azure Web App Service, and Azure DevOps project with permission to configure the Pipeline and to add a new service connection to the Azure Resource Group. If you are not sure about how to configure the Service Connection to the Azure Resource Group, this post will help you.
Create the YAML files needed
We will be creating 3 YAML files as listed below.
- A template file with the all the tasks, so that we can reuse them for the environment specific pipelines
- A pipeline for Test environment
- A pipeline for the production environment
Let’s configure all the tasks needed in our template file. We will have 2 stages in our template. You can read this post if you are not sure how to configure the stages in the pipeline.
- Build stage, for performing the tasks below
- Install .Net Core SDK
- .Net restore
- .Net build
- .Net publish
- Publish to Azure DevOps artefacts
- Deploy stage, to deploy the artefacts generated to the Azure Web App Service. This will involves the taks below.
- Download the artefact
Our final template file will look like this.
Add pipeline for Test environment
As we have a template available, we can use this to configure the pipeline for our test environment. All you have to do is to refer to this template and pass the required parameters. This is how our pipeline for our test environment can look like.
Here, the parameter azure subscription is the service connection name that you have created in your Azure DevOps project. Refer to this to know more. The wwebAppName is the name of your Azure Web App Service.
Add pipeline for Prod environment
Let’s create a new pipeline for our Prod environment to see how easily we can reuse the template.
Wasn’t that cool?
Configure the pipelines in the Azure DevOps
Just creating the YAML field will not create the pipelines in our DevOps, as Microsoft has removed that option due to some security concerns. So we will have to configure them manually for the first time. Let’s do it.
- Go to the Pipelines section from your Azure DevOps and click on the New pipeline button.
- Select Azure Repos Git (YAML) from the next screen.
- Select the repository that you pushed your YAML file code changes.
- Azure DevOps will analyze your repository and sugges the YAML templates. Select the Existing Azure Pipeline YAML file option.
- Selct the branch and the path to your YAML file as in the preceding image, review the same and run the pipeline.
That’s it. Everything else will be working as expected from the next time as we have configured the triggers in the pipelines. If you are getting an error as “Task “NETSdkError” skipped, due to false condition; (‘$(_TargetFrameworkVersionWithoutV)’ > ‘$(NETCoreAppMaximumVersion)’) was evaluated”, you will have to make sure that you are installing the correct version of the .Net Core SDK as mentioned in this answer.
You can get the complete source code from this GitHub repository. Please feel free to fork/star.
Here in this post, we have learned the following things.
- How to configure a YAML template
- How to reuse a YAML template in the pipelines
- How to deploy the .net 6 application to Azure Web App Service
About the Author
I am yet another developer who is passionate about writing and video creation. I have written close to 500 blogs on my blog. And I upload videos on my YouTube channels Njan Oru Malayali and Sibeesh Passion. Please feel free to follow me.
Your turn. What do you think?
Thanks a lot for reading. Did I miss anything that you may think is needed in this article? Could you find this post useful? Kindly do not forget to share your feedback.