5

I am trying to automate installing a "zip" package files from Sitecore's installation wizard.

But I'm unable to work out how to allow an automation using PowerShell DSC to log in and trigger the install from here...

Can someone help me on this? The Installation Wizard in the menu tree

5

You can install packages via DSC - but I don't think automating the UI is the right way to go about it. When I worked through this issue I dealt with it by creating an endpoint that DSC can push the packages to without bothering with the UI:

Dependencies for getting the install done

First up, you'll need an endpoint to trigger the install. My DSC approach was based on an approach I first tried using plain PowerShell. The endpoint I used was a simple ASPX file that I grabbed from someone else's work on GitHub. The file was: https://github.com/adoprog/Sitecore-Deployment-Helpers/blob/9c93812f799216c4c676f800fb2a3f083bf73fd9/InstallModules.aspx However that's not the only example of this approach that exists, and you could just as well use someone else's endpoint file.

All that's important is that you end up with something you can deploy with a file copy and can call Sitecore's internal package management APIs as a result of an HTTP POST or GET operation.

Getting the endpoint installed requires two things: Your DSC needs to know where the file is, and it needs to copy it over.

Knowing where to find it is easy - just extend the config data you already have for your DSC script in your .psd1 file. I added the PackageInstallFile property, and made sure that this file (from the repo linked above) was copied into the same location that all my other dependency files like the Sitecore installer were put in:

@{
    AllNodes = @(
        @{    
            WWWRoot = "C:\inetpub\wwwroot"

            Sitecore = @{ 
                InstanceName = "MyInstance"

                PackageInstallFile = "PackageDeploy.aspx"      <<-- This bit is new
            }
         }
    );
}

Then you need a DSC resource to do the install. That's just a file copy:

File AddRemoteDeploy
{
    DependsOn = "[script]InstallSitecore"
    SourcePath = "$PackagePath\$($Node.Sitecore.PackageInstallFile)"
    DestinationPath = "$($Node.WWWRoot)\$($Node.Sitecore.InstanceName)\website\$($Node.Sitecore.PackageInstallFile)"
    Type = "File"
    Ensure = "Present"
}

The DependsOn property here needs to ensure this runs after you've installed Sitecore, so make sure the resource name matches yours.

Something I found that was also useful here was to make sure you "warm up" Sitecore and get it loaded into memory once you've done this bit of the install. (See my blog post on this topic for the script) as this helps ensure you don't get timeouts for the package installs.

The install itself

Once you've done that, you just need to call the package installer endpoint.

I don't have a blog post on general package installs via this route for DSC (Though the logic is much the same as the pure PowerShell approach here), but I did write up how to install the Coveo for Sitecore zip package like this here: https://jermdavis.wordpress.com/2015/12/07/development-environments-with-powershell-dsc-part-7/ and you can adapt that for general installs. The key bits are putting the zip package into the right folder and calling the endpoint to trigger Sitecore to install it.

You need to have some config to describe the package to install:

@{
    AllNodes = @(
        @{    
            WWWRoot = "C:\inetpub\wwwroot"

            Sitecore = @{ 
                InstanceName = "MyInstance"
                PackageInstallFile = "PackageDeploy.aspx"

                NameOfYourPackage = "MyPackageFile.zip"     <<-- This bit is new
            }
         }
    );
}

That package file needs to end up copied over to Sitecore's Package directory:

File AddThePackage
{
    DependsOn = "[script]InstallSitecore"
    SourcePath = "$PackagePath\$($Node.Sitecore.NameOfYourPackage)"
    DestinationPath = "$($Node.WWWRoot)\$($Node.Sitecore.InstanceName)\Data\packages"
    Type = "File"
    Ensure = "Present"
}

Then you can call the endpoint:

Script InstallAPackage
{
    DependsOn = "[file]AddThePackage"
    GetScript = {
        @{ Feature = "Install A zip package for Sitecore" }
    }
    TestScript = {
        $folder = "$($using:Node.WWWRoot)\$($using:Node.Sitecore.InstanceName)\Website\SomeFileOrFolderThePackageCreates"
        Test-Path -Path $folder
    }
    SetScript = {
        $siteName = $using:Node.Sitecore.InstanceName
        $sitecoreFolder = "$($using:Node.WWWRoot)\$($siteName)\Data\packages"   

        $module = "$($using:Node.Sitecore.NameOfYourPackage)"

        $query = (Split-Path -Path $module -Leaf)

        Write-Verbose "Calling package upload tool for $using:query"

        $url = "http://$siteName/PackageDeploy.aspx?modules=$query"
        $result = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 600 -OutFile ".\$siteName-PackageResponse-$query.log" -PassThru

        if($result.StatusCode -ne 200) {
            Write-Verbose "StatusCode: $($result.StatusCode)"
            throw "Package install failed for $query"
        }
        else {
            Write-Verbose "Install ok"
        }

        $file = Join-Path $sitecoreFolder $query
        Remove-Item $file -Force
    }
}

Depending on the size of the package, that step may take a while. The code above tries to avoid timeouts (especially if combined with the warm-up script discussed above) but you may need further tricks for really big packages or slow servers.

The example above does only a single file, but you can extend it to install multiple things in sequence by extending the config and putting a for-loop around the install process...

(This is typed from memory - apologies in advance for any typos I've made)

  • Davis when I am trying same logic with a different aspx file am getting some error. could you please help me here .. posted error at below link sitecore.stackexchange.com/questions/4998/… – Vamsi Krishna Mar 19 '17 at 15:01
  • @JermDavis, I'm trying to install a sequence of big modules. I've tried several versions of the "PackageDeploy.aspx" page without much success. When installations require several site re-starts, then the "PackageDeploy.aspx" page returns "successful" result while the first installation didn't finish yet. Once a few installations are overlapped, Sitecore hangs and stop working any more. I need the PowerShell code to be able to know when the install is actually over (regardless of any number of sitecore re-starts). If you know any available solution for this, please let me know. – Ben Jun 17 '18 at 15:26
  • Stretching my memory back a few years - but I seem to remember my issues around that were mostly related to "does the PowerShell HttpRequest time out before Sitecore restarts and finishes the install" - do longer timeouts help? Alternatively, if restarts are due to the package containing DLLs and/or config files? Are you able to split the package up into an items package and a "stuff that triggers a restart" package? Maybe that would help? – JermDavis Jun 18 '18 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.