Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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);
}
share|improve this answer
3  
It can be done even simpler: while($mySolution.JobExists) so you would probably give an SPSolution as param instead –  Anders Rask Jun 1 '12 at 8:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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