Azure DevOps CI/CD Pipeline to deploy . net core application onto an IIS server
This article will demonstrate how to deploy your . net core app on an IIS server via a pipeline configured in azure devOps.
Overview
To publish a . net core web app to a IIS server in an azure virtual machine.The main objective of this project was to configure, build and release pipelines to deploy the web app.
Step 1: Setup the build pipeline
Two ways to setup the build pipeline.We can click on setup build, which will provide us most relevant build templates per the source and create the pipeline with YAML. Else we can go from the scratch by selecting pipelines → new pipeline → use the classic editor.We need to select the version control, project, repository and the branch to trigger the build. Providing the required data will take you to the editor to select a template.
We need to select the version control, project, repository and the branch to trigger the build. Providing the required data will take you to the editor to select a template.
Select the ASP.NET Core template
Build pipeline is defined with four task
Enabling Continuous Integration
Select the Triggers to view the option to enable continuous Integration here we check the box to enable it and in the branch filters we have two options Exclude and Include in our case we will include the branch whenever new commits are done.
Now we can manually trigger the pipeline and watch the pipeline work.
Step 2: Creating a Azure Virtual machine with Azure cloud
Sign in to the azure portal always create your resource group first in the region where deployment is gone be done.In the search tab search for the virtual machine. Here we are going to create Windows Server 2019 VM for our deployment.
In order to connect to the server, we use RDP. Disk,Networking,Management and Advanced we will set the default values.
Navigate to the Virtual machine resource → overview. Here you will see the analytics of your VM for the selected duration.
Step 3: Setup IIS in azure virtual machine
After login into the VM open the server manager
search for server manager → Add roles and features → Next (Before you begin) → Installation Type (Role based or feature based) → Server selection (Select server from pool) → Server Roles (Enable Web Server (IIS)) → Features (Enable .Net Framework 3.5) → Web server Roles → Role Services (Enable IIS 6 Management compatibility)
Step 4: Setup release pipeline
In order to deploy the web application to IIS we should create a deployment group and provision a service agent in our windows server 2019 in the virtual machine.
1. Deployment group
A deployment group represent the environment that the application will be deployed to. It is a set of target machines each having a service agent installed.
Navigate to pipelines → deployment groups in azure devops. Click on +New to create a new deployment group.
Now we need to install the service agent into the target machine. To install, the generated script must be executed in the server powershell as an admin. To authenticate the script we must attach the personal access token of the user to the script. Devops will create a token and handle that for you if you check the check box highlighted in the following image. If the token is attached, we are not prompted to enter the authentication type and the credentials. Else will have to provide the type and the credentials.
As mentioned in the above figure, while registering the agent it will prompt for several requirements.
- Enter replace →y
- Group tags → y
- Add tags → dev, prod (to specify the scope the deployment group will be handling we using tags)
- Add credentials we used while creating the vm as we are logged in to the vm through that account.
Now check the deployment groups in azure devops. You will see the following. The agent is installed and the group is active.
Step 5: Setup release pipeline
We are almost done now. Go to releases → new release if no prior releases. Follow the above images. Will explain after the figures.
Select IIS Deployment and add the correct deployment group we configured. If you need to strictly specify the scope of the deployment use the tags you added while registering the agent. And make sure the artifacts are taken from the correct build.
Enable IIS check will be a good option to check if the iis is installed in the target machine or not. And action as create or update will check for the existing website with the same name and if exist it will update else will create new one. Make sure the path is correct. it should be the root folder of iis. If you need to customize the url bindings. unlink the parameteres from the Job itself and add as preferred. For now i am keeping the hostname undefined which is equal to the localhost of the iis server.
Navigate to the release displaying in top. click on the logs button to view the logs. Successful deployment will show the below figure.
As the final step you can navigate to the iis server in azure vm by going to server manager → iis → select server and right click → select iis manager and go to the site deployed and browse.