Setup ‘Azure DevOps’ — CD/Release build for Sitecore Habitat — Part 5!
Welcome back!
If you are reading this blog post, hope you would have viewed the other blog posts. Its motivating to see the comments & claps to the posts added, happy to share the knowledge to the Sitecore community.
You will find serious of blog post (links below) on Habitat project, explains how to setup end to end Azure DevOps Pipeline setup.
Part 1: Setup Sitecore Habitat with Sitecore 9.0 Update 2 in 30 Minutes!
Part 2: Setup ‘Sitecore Habitat’ to ‘Azure DevOps’ repository!
Part 3: Setup ‘Azure DevOps’ CI build for Sitecore Habitat
Part 4: Setup ‘Sitecore PaaS’ from Azure Marketplace!
Part 5: Setup ‘Azure DevOps’ CD/Release build for Sitecore Habitat
The below is a temporary solution, I found an issue when federated authentication is enabled, the Habitat site is not working in Sitecore PaaS. So I am temporarily commenting the federated authentication related code. I will try to blog separately why federated authentication is not working in Sitecore PaaS in future.
Follow the below steps to comment the Federated Authentication in the Habitat Project.
1. ‘Feature.Accounts.config’ file
- Set the Federated Authentication enabled to ‘false’.
- Comment the IdentityProvider.
2. ‘Habitat.Dev.config’ file
- Set the Source folder as ‘$(dataFolder)\unicorn’
3. Habitat.Website.config
- Comment the federatedAuthentication element
- Update the ‘Sitecore PaaS’ Url in the targetHostName.
4. Check in the 3 files to Visual Studio online / Azure DevOps Repository.
Automated Release (Continuous Deployment)
Let’s see how to setup the Automated Release build to Sitecore PaaS.
- Once you committed the configuration changes to Source Repository, as mentioned in the previous section, queue a new build.
- New build queued and in-Progress
2. While the build is in progress, create a new Release Pipeline.
- Create a new Release Pipeline
- Select the Template as ‘Azure App Service Deployment’ and click Apply.
- Change the Stage Name as required, I have changed to ‘PaaS Deployment’
- Select the Tasks and configure the Azure subscription & Azure App Service Details and Save.
- Configure Task ‘Deploy Azure App Service’. Setup the Post Deployment Action as inline Script.
- Update the Deployment script to copy the build ‘Output’ to ‘Root folder’ and App_data\Unicorn folder.
xcopy D:\home\site\wwwroot\Output\* D:\home\site\wwwroot\ /e /i /y
xcopy /s /y d:\home\site\wwwroot\data\unicorn\* d:\home\site\wwwroot\app_data\unicorn\
- Save the Pipeline by changing the name you wish, I have given the name as ‘My Habitat PaaS Deployment’
3. Configure the Pipeline Task by adding an Artifact by selecting the source build pipeline.
- Once successfully creating the release pipeline, you can create a release.
- Create a New Release by selecting the latest artifact version.
- Once you create a release, select the Release 1 and select PaaS Deployment.
- Manually trigger the deployment.
- Once manually triggered deployment, you can check the logs.
- Check if the ‘PaaS Deployment’ is completed or Succeeded.
4. Check if the Website is running, you will see the layout error.
- Check if the Unicorn files are copied to the ‘App_Data\Unicorn’ folder using Kudu tool.
- Go to Portal Azure.
- Its time to sync the Unicorn content manually.
I will keep you posted to run this automatically unicorn automatically post deployment.
- Lets check a sample file exists in the Output folder. In this, I could see the Item Buckets Settings.yml found in the ‘BucketSettings’ folder
- Lets check the same sample file available in the App_Data\Unicorn folder. In my case found the files are not copied only the folder are copied.
- Copy manually the files using xCopy command.
xcopy /s /y d:\home\site\wwwroot\data\unicorn d:\home\site\wwwroot\app_data\unicorn
- Now I could see the file Item Buckets Settings.yml found in the ‘BucketSettings’ folder
- So Build the Unicorn URL and check if the configurations are loaded successfully
https://<Sitename>-<number>-single.azurewebsites.net/unicorn.aspx?sc_lang=en
- Since running the each configuration separately (manually) takes time, so lets build another url to sync automatically all the configurations.
https://<sitename>-<number>-single.azurewebsites.net/unicorn.aspx?verb=Sync
- Once 100% unicorn sync complete open the Content Editor and Goto → Publish → Publish Everything → Publish all Languages.
The below are steps to add unicorn sync as part of the Release Pipeline. This will reduce the manual deployment. Kindly consider this as reference.
Add a task to sync the Unicorn
Add Unicorn Sync to your Organization.
Install the Unicorn Sync to your Organization
- Update the configuration details for unicorn sync like Control Panel URL & Shared Secret.
- Shared Secret you can find in the ‘Unicorn.SharedSecret.config’ on the solution.
- Ensure you update the web.config with CodeDom. Update the Same using Kudu Editor
<system.codedom>
<compilers>
<compiler language=”c#;cs;csharp” extension=”.cs” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel=”4" compilerOptions=”/langversion:6 /nowarn:1659;1699;1701" />
<compiler language=”vb;vbs;visualbasic;vbscript” extension=”.vb” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel=”4" compilerOptions=”/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+” />
</compilers>
</system.codedom>
Finally you will the Habitat site is running on the Azure.
Temporary Fixes !!!
The below are fixes to make the Habitat Site working in the Sitecore PaaS. These may not be required in production version, these information will help you to understand how to make the Sitecore website work in the Azure PaaS
- Check the SourceFolder.
2. If you face any error.
Server Error in ‘/’ Application.
Cannot create identity provider with nonexistent sitecore domain “facebook”
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Cannot create identity provider with nonexistent sitecore domain “facebook”
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Cannot create identity provider with nonexistent sitecore domain "facebook"]
Sitecore.Owin.Authentication.Configuration.DefaultIdentityProvider.set_Domain(String value) +165
Solution
Comment the Facebook Identity, this is not permanent solution, but this helps.
3. If any error like the below
Could not find configuration node: federatedAuthentication/identityProviders/identityProvider[@id=’Facebook’]
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not find configuration node: federatedAuthentication/identityProviders/identityProvider[@id=’Facebook’]
Solution:
Again this is not permanent solution, but this will fix the issue for now.
4. If you any issue like
Identity provider “Facebook” was not found in configuration.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Identity provider “Facebook” was not found in configuration.
Solution
5. Unicorn not showing the content to sync.
Warning: your current predicate configuration for at least one configuration does not have any valid root items defined. Nothing will be serialized until valid root items to start serializing from can be resolved. Please review your predicate configuration.
There are dependencies between some configurations, therefore the order in which you sync them is important.
Configurations
Foundation.Serialization
Sitecore.Solution.Framework Root items
Solution:
Double check whether the folders contain all the required .yml files, in my case, just folder got created there was no .yml files exists in the folder.
6. Invalid Expression term ‘.’
Solution:
Add in Web.config.
<system.codedom>
<compilers>
<compiler language=”c#;cs;csharp” extension=”.cs” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel=”4" compilerOptions=”/langversion:6 /nowarn:1659;1699;1701" />
<compiler language=”vb;vbs;visualbasic;vbscript” extension=”.vb” type=”Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel=”4" compilerOptions=”/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+” />
</compilers>
</system.codedom>