Removing Gulp from your CI Pipeline for Helix style solution with PowerShell

As previously discussed, if you have an Helix style solution, and you want to replace Gulp with PowerShell this script can come quite useful…

The principle is not to use Gulp for Build and packaging neither on your local environment (see this other post to see how to do it: https://sitecorecommerce.wordpress.com/2019/11/02/powershell-to-publish-helix-base-solution-with-visualstudio-2019-without-gulp/

neither on your Build server / Azure Pipeline….

as you can imagine PowerShell is your friend 🙂

In my specific example, I have instrumented it with VS 2017 but this script would work with any version of MS Build assuming that all parameters are supported….

BuildAndPublish

The principle is a pretty simple loop through all the project in Feature / Foundation / Project and just calling a simple MSBuild command to publish the project within my Temp folder….  Msbuild will build each project, and publish each project copying the Bin / Views / and configs in the Temp folder keeping your solution structure…

Once you have the temp folder, you can then Zip the package and use to deploy on your Sitecore instance…

 

Copying Unicorn Files With PowerShell for Azure Pipeline within an Helix style solution without GULP

In the case, you have an Helix style solution, you are using Unicorn and you use Azure Dev ops as your build pipeline to publish your solution on Azure PAAS and you want to use Gulp only for styles and scripts manipulations…

you will definitively need this snippet since you probably have already encountered this problem within your Build Pipeline…

The principle is pretty simple, you need to copy your YML files and keep all the folder structure within serialization… within the App_Data/Unicorn folder within a website Temp folder that you will later zip with the rest of Bin and Views so that you can install your changes once the package is deployed across the environment…

This is done within the Gulp – Package task typically, but if you want to get rid of it, I would recommend doing a separate PowerShell Task just to copy Unicorn files…

copyunicorn

The content of the Powershell is pretty simple and copy the files keeping your serialization structure across Feature, Foundation, Project folders…

Disaster Recovery region in Azure for Sitecore 9.x

In case you are worried about an Azure region going down and want to make your Sitecore Azure infrastructure not dependent on a single region, deploying a region for disaster recovery could be an option…

Obviously, depending on the complexity of your website, Sitecore resilience may be the minor problem in case of a region failure and further conversation should be taken to ensure that your infrastructure and data can be available across multiple regions….

As you can imagine, if your site is relying on Sitecore Analytics for personalization features your task won’t be trivial due to the Sitecore architecture, however, is a fair assumption and common practice to have analytics turned off on the DR region…

A typical DR region for Sitecore, would need the following elements:

  • Content Delivery server
  • WebDatabase
  • Redis cache (you could consider switching off if budget is an issue)
  • Search (assuming that is mandatory to have search available in case of DR)

My recommendation to provision a DR region on Azure PAAS would be to use the XM scaled scripts to provision a new environment in your favourite “backup” region and then delete the unrequired resources:

  • Identity server
  • Content Management Server
  • Master Database

The following Powershell script shows how to run the clean up of these resources…

 

Sitecore 9.2 Powershell using ARM Template for Azure PaaS

As you have probably heard, SAAS is coming summer 2020… but if your Sitecore project cannot wait that long, ARM templates are what you need to provision your Sitecore application on Azure PAAS…

In case you have no idea where to start, a few things that you need to know and decide

Sitecore Topology: you will have to choose between XM in case you do not need analytics and XP in case you need the fully flagged platform…

The topology is very different adding several additional configurations and servers in case you decide to go with the analytics….

Size of your installation, this will preset the size and kind of services provisioned, the default setting is extrasmall so that you can save on costs….

The url to get the Sitecore templates for 9.2 is https://github.com/Sitecore/Sitecore-Azure-Quickstart-Templates/tree/master/Sitecore%209.2.0

In addition to this, you will need the WDP packages for the topology selected https://dev.sitecore.net/Downloads/Sitecore_Experience_Platform/92/Sitecore_Experience_Platform_92_Initial_Release.aspx# don’t forget to download WDP for the identity server…

In addition to this, you will need a valid sitecore license, an azure subscription and you can provision a certificate for your test instance….

Once you have all the resource ready you will have upload on azure the WDP and the ARM templates in a storage account / Container…

Assuming you are going for the XM Scaled template, will look like:

azure

once you are ready with thearm template, you can start editing your powershell required for trigger the deployment:

here is a very good example…

https://github.com/Sitecore/Sitecore-Azure-Quickstart-Templates

once you are ready to start provisioning, keep calm since the XM templates took more than 30 minutes and the XP scaled will take you more than one hour to complete…

in case you are working with test certificates, do not forget to add a allowInvalidClientCertificates parameter and set it to true in the parameters.json file…

Also worth mentioning that the key command to launch to provision your infrastructure is New-AzureRmResourceGroupDeployment -ResourceGroupName $Name -TemplateFile $ArmTemplateUrl -TemplateParameterObject $additionalParams -Debug -Verbose

note that the additionalparams is a hashtable generated from the parameters.json…

Powershell to publish Helix base solution with VisualStudio 2019 without GULP

As most of Sitecore developers I quickly fall in love with Helix base solution approach but when it comes to developer experience Gulp was not feeling like the best match for build and deployment neither on my local machine…

As you have probably experienced, getting Gulp up and running is pretty simple, but as you start adding projects and complexity to your solution the build time increase exponentially and I have seen solutions where the Gulp build task taking more than 20 minutes, compared to 1-2 minutes of a standard Visualstudio build & publish command….

Therefore my idea to use Powershell even to deploy on my local machine for a full build and publish of my solution locally…

The idea is to hook in the full build and publish of all the projects on the publish of the main website project…

In reality, the code to achieve it, it is pretty simple and you can get it to work pretty easy since you need to worry only about three areas:

  1. Clean up of configs
  2. Build and publish of all the projects
  3. Copy configs that did not come after the full publish

As additional steps, you may consider including the Unicorn or TDS synchronisation to replicate what you do within Gulp but personally, I like to run manually all the items synchronisation to keep closer control and have quicker build and publish time…

Few things to do to get it running:

1.  Install prerequisites

IIS Management Script and Tools must be enabled from ‘turn windows features on or off’

preReqPS.JPG

2. Copy the powershells script and powershell config in the website – configuration folder

You need these two files from my Gist: https://gist.github.com/steliodibello/4cb47563ce43b922b943a000ec072853

remember to replace XXX with your project name

3. Amend the main webiste project to invoke the powershell on the after build step

<Target Name=”PublishAll” AfterTargets=”CopyAllFilesToSingleFolderForPackage”>
<Exec Command=”powershell.exe -NonInteractive –ExecutionPolicy Unrestricted -command &quot;&amp; { &amp;’$(SolutionDir)Configuration\PostPublish.ps1′ -solutionPath ‘$(SolutionDir)’ } &quot;” />
</Target>

 

For further reference and similar blogs who have inspired mine, have a look at:

https://www.onceinawhitemoon.net/2019/04/automatically-deploy-all-sitecore-helix-projects/

and

https://whipeter.wordpress.com/2018/09/07/sitecore-helix-build-and-deploy-powershell-script/