Azure Devops Pipeline Deployment of .NET Web App and SQL Server database to IIS:
- Login to Azure Devops at: https://dev.azure.com
- Click on Pipelines on the lefthand column
-
Click on New pipeline on the top right corner:
-
Your screen would then look like this:
-
Click ‘Use the classic editor
-
Select the Repo and Branch from Azure Repos (or GitHub in this case) and click Continue:
-
Select the ASP.NET template and click Apply:
-
Your pipeline for building the application is almost complete:
- Next, click Save & queue at the top, then Save & run:
-
Wait a few minutes for the build pipeline to start and finish. There should be a success message at the bottom of the screen:
-
A drop folder should be created within the Artifacts section:
-
For this application, we have a database that we need to deploy. (Skip this step if you don’t have a database.) We need to copy the DACPAC(SQL Server Database backup) file to the artifacts directory, as you can see it’s missing above. The release pipeline that is created later needs the DACPAC file to deploy to SQL Server. So, in the build pipeline, click the ‘+’ sign to add a task and select ‘Copy files’ and click Add:
-
In the Copy Files task, rename it to ‘DACPAC’ or something to make it clear what the task does. Then, set the Source Folder to the ‘db’ directory (in this case that’s where the DACPAC file is stored), and set Contents field to ‘**’, and the Target Folder to ‘$(build.artifactstagingdirectory)’ as that will allow the Release Pipeline to find the DACPAC file:
-
When you run the build pipeline again, it should have the DACPAC file in the drop directory:
-
Next, we need to create a deployment Group or Groups (if you want to separate your deployments to multiple servers in the future). In this case, I’ve kept it simple to just have one deployment group to handle one connection to a Windows Server which contains both IIS and SQL Servers. Under the Deployment Groups menu, create a new deployment group. You should see something like this after setting the name:
-
Copy the Powershell script to the clipboard along with the token:
-
Next, open a powershell Window as an administrator, and paste the script into the window, and press enter to run. Follow the directions as required:
You now have a deployment group setup, with an Azure agent running on your server! This will allow the actual deployment of your application and Database to the server to happen.
-
Next is the creation of a Release Pipeline. First, click Releases on the left menu, then New release pipeline:
-
A basic release pipeline is created for you:
-
Select the IIS Website deployment template and click Apply :
-
Click on Add an artifact:
-
Select the build pipeline that you created previously and click Add:
-
Click on the Stage 1 tasks link to see your newly created release pipeline:
-
On the Stage 1 bar, click Unlink all, as you’ll need to manually set all options.
-
Next, click on the IIS Deployment bar, and Enter the correct Deployment group. Also, in the Required tags field, enter any tags you may have entered when setting up your Deployment Group (or you can enter none if you only have one server to deploy to):
-
Click on IIS Web App Manage and enter the Website name and Physical path. Make sure to enter something different than the Default Web site:
-
Click on IIS Web App Deploy and enter the same Website name and the correct .zip file name:
-
Next, Click on Deploy using: dacpac. Make sure to select the correct DACPAC file from the drop directory and set the Server Name, Database Name and Authentication to these values shown:
-
Click Save, then Create release, Create again, Click on the Release link to watch the release being deployed to IIS!:
- When you see the success message, it has been successfully deployed to IIS AND SQL Server!
-
Test your application to ensure it’s working. Here is what you should see if you’ve successfully deployed the demo application from my public github Repo: