Question

I have a problem with a update of a solution on farm. So we have changed some features and added two features. The main changes were done to the main feature of the solution.

On our test cloud it workes fine. On our test environment it first works fine, but after a redeployment it have not worked any more. The updated features were not completly installed. This happends at the customer environment too and some other test deployments have got the same problem.

So we have changed the update script we provided. In this point we have a sleep time between the Update-SPSolution command and the Upgrade of all features of the deployed features. We raised the sleep time from 20 seconds to 5 minutes.

A new update now went fine, but we wanted to recreate the old state and installed the solution with the old update file again, but this works fine too ;-). (yeah thats a worse situation)

The important update process looks this way:

Update-SPSolution -LiteralPath $wspFile -Identity $fileName -Force -GACDeployment -ErrorAction:Stop -ErrorVariable:updateError -Confirm:$false
Start-Sleep -Seconds $sleep
$site = Get-SPSite $SiteUrl
$siteFeatureToUpgrade = $site.QueryFeatures("Site", $true);
foreach($f in $siteFeatureToUpgrade)
{
    $f.Upgrade($false);
}

The value of sleep is once 20 and once 300. Anyway, could it be that this sleep time resolves the update issue? Cause I dont think so.

Thank you very much.

Was it helpful?

Solution

The Update-SPSolution call is asynchronous. More precisely, this command only create a timer job that will be run eventually.

You can use this function to wait for the end of the execution of the job :

function Wait-SPSolutionDeploymentJobToFinish
{
    param
    (
        [Parameter(Mandatory=$true)]
        [string]$SolutionFileName
    )
    process {
        $JobName = "*solution-deployment*$SolutionFileName*"
        $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
        if ($job -eq $null) 
        {
            Write-Host 'Timer job not found'
        }
        else
        {
            $JobFullName = $job.Name
            Write-Host -NoNewLine "Waiting to finish job $JobFullName"

            while ((Get-SPTimerJob $JobFullName) -ne $null) 
            {
                Write-Host -NoNewLine .
                Start-Sleep -Seconds 2
            }
            Write-Host  "Finished waiting for job.."
        }
    }
}

Update-SPSolution -LiteralPath $wspFile -Identity $fileName -Force -GACDeployment -ErrorAction:Stop -ErrorVariable:updateError -Confirm:$false


#Start-Sleep -Seconds $sleep
Wait-SPSolutionDeploymentJobToFinish $fileName

$site = Get-SPSite $SiteUrl
$siteFeatureToUpgrade = $site.QueryFeatures("Site", $true);
foreach($f in $siteFeatureToUpgrade)
{
    $f.Upgrade($false);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top