In the previous article, you have learned how to build your solution with Azure DevOps.
Continue reading this if you are not just interested in verifying the integrity of your source codes but also want to deploy that updates to somewhere else, in particular to your website hosted in Azure App Services.
In the Releases menu of your project, click on the New -> New Release Pipeline:
Similar to the build pipeline, Azure DevOps will offer you a number of templates to choose from
You might be tempted with choosing the Azure App Service deployment template.
However, this template contains only a single task to push your package to Azure App Service. If your website is purely built from .NET dlls, this should be sufficient. However, your Sitecore solution will need more than that.
Again, I will choose the Empty Job option instead:
You will notice the pipeline contains 2 parts:
- Artifacts: this is where you get the build package generated in CI process
- Stages: this is where your build package will go through stage(s) to be deployed
Click the "Add an artifact" link, it will prompt you to choose the source type where the artifacts come from:
Since you have already had the build package generated from the CI process, choose the source type as Build.
You can use other source types such as from other repositories but it is not recommended. You want to be able to separate the CI and CD processes as much as possible so in case anything happens, you can find out which process went wrong without investigating everything.
After choosing the Build source type, you will need to choose the project and build pipeline as the source:
There are a few options to choose under "Default version". The simplest one is "Latest" if you want the build package with latest codes.
Click Add button and you are done with getting build package from CI process:
If your deployment has multiple stages that it needs to go through, you can add more stages. Otherwise, only one stage is required to deploy your Sitecore solution. Within this stage, you will need to add a number of tasks by clicking on the link in the stage. It will bring you to the tasks list page:
Similar to the tasks in CI process, you will also have an agent job that is responsible for running the tasks in CD process. Add the following tasks to the agent job:
- cURL Upload Files
You will need this task to upload your Sitecore .update packages to a location in your server:
You can either browse the Files field to locate the exact .update file in the path. If you have multiple packages, you can use the wildcard *.update to find all of them.
In order for Azure DevOps to push the files to Azure App Services, you will need an authentication mechanism between them. For cURL Upload Files task, you can use FTP. The following details will be required:
You will need to specify the exact location where you want to transfer the files to:
You might notice the folder structure that contain the /App_Data folder of Sitecore 9 instance then followed by the /SitecorePackageDeployer folder.
This folder will be created automatically when you install the Sitecore Package Deployer module from here: https://github.com/HedgehogDevelopment/SitecorePackageDeployer/releases
The Sitecore Package Deployer module have 2 modes: Scheduled and On Demand. If you drop the .update files to that location, the schedule if enabled will pick them up and install in your Sitecore instance at scheduled interval.
However, if you want to see the Sitecore updated items immediately after CD process is complete, you have to set up the next task to use On Demand mode
- Sitecore Package Deployer
In this task, you need to specify the URL of your Sitecore website in the "Sitecore URL" field:
Since you will be hosting your Sitecore solution in Azure App Services, you will have multiple servers for CD, CM, Reporting, etc. The Sitecore URL is your CM website URL.
Check the "Force Package Deployer Process" to ensure it always run when being requested.
- Azure App Service Deploy
Finally, set up this task to deploy your .zip website file (dlls, views, config, etc) to the target server:
The following fields are required:
- Azure subscription – you will need an available Azure service connection. If you do not have a service connection, click on the Manage link above to set it up. You can read the guide to setup a service connection here: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=vsts
- App type – choose default value which is Web App
- App Service name – once you have the available service connection, you can see a list of App Services. In this task, you can select the CM App Service
- Repeat step 3 to create additional deployment task for CD App Service
Now save the tasks then click the Pipeline menu. You have a final step to do:
You have already set up the Artifacts & Stages. You will need to link them together.
Click on the "Continuous deployment trigger" icon:
In this menu, choose "Enabled" for "Continuous deployment trigger" then add the branch that will trigger it:
After saving the pipeline, you can trigger a release manually to test with "Create a release" option:
If you are like me, you will think that the release will be successful when you see the green ticks on this page:
But I was wrong when I check the deployment. My website codes were deployed perfectly. However my Sitecore update packages were not.
After hours of research and scratching my head, I finally found the failure at Sitecore Package Deployer task.
This task behind the scene will call the URL: https://your-sitecore-url/sitecore/admin/startsitecorepackagedeployer.aspx
However, this /sitecore/admin section do not allow anonymous access by default. You will need to update the Web.config of the CM site to allow it by adding this config section:
In the past, we can use Sitecore Ship task to achieve the deployment of Sitecore package. However, it is reported that Sitecore Ship does not work on Sitecore 9. Hence the only choice left is to use Sitecore Package Deployer.
I hope by the end of this article, you can manage to successfully deploy your Sitecore 9 solution to Azure App Services from Azure DevOps.