3

.wsp パッケージを自動的にビルドし、各コミット後にステージング サーバーに再デプロイしたいと考えています。継続的インテグレーションのために CruiseControl.Net をセットアップする方法は知っていますが、パッケージをビルドしてデプロイする方法はわかりません。これまでのところ、 MSBuild で .wsp ファイルを生成するようになりましたが、自動再デプロイ スクリプトに苦労しています。これまでに取得したのは、PowerShell スクリプトです。

param([string]$siteUrl = "http://machine.local")
$ErrorActionPreference = "Stop"

function WaitForPendingJob
{param ($sol)
    $counter = 1
    $sleeptime = 2
    $safeguard = 100
    while( $sol.JobExists -and ( $counter -lt $safeguard ) ) {
        Write-Host -f yellow -NoNewLine "."
        sleep $sleeptime
        $counter++
    }
    Write-Host ""
}

function InstallOrUpdateSolution
{param ($SolutionWsp, $SiteUrl, $featureGuid)   
    $FullPath = resolve-path $SolutionWsp
    $farm = Get-SPFarm
    $sol = $farm.Solutions[$solutionWsp]
    if ($sol)
    {
        Write-Host -f Green "Going to uninstall $SolutionWsp"
        if( $sol.Deployed -eq $TRUE )
        {
            Write-Host -f Green "Deactivating feature $featureGuid at $SiteUrl" 
            Disable-SPFeature -Identity $featureGuid -Url $SiteUrl -Confirm:$false -force -ErrorAction Continue
            Uninstall-SPSolution -Identity $SolutionWsp -WebApplication $SiteUrl -Confirm:$false -ErrorAction Continue
            Write-Host -f yellow -NoNewLine "waiting for retraction"
            WaitForPendingJob $sol

        }
        Write-Host -f Green "$SolutionWsp is retracted."
        Write-Host -f Green "Going to Remove $SolutionWsp"
        Remove-SPSolution -Identity $SolutionWsp -Force -Confirm:$false -ErrorAction Continue
        Write-Host -f Green $SolutionWsp is deleted from this Farm
    }   

    Add-SPSolution -LiteralPath $FullPath
    Install-SPSolution -Identity $SolutionWsp -WebApplication $SiteUrl -GACDeployment -CASPolicies -Force
    $sol = $farm.Solutions[$SolutionWsp]
    if ($sol.Deployed -eq $false ) {
        write-host -f yellow -NoNewLine "waiting for deployment"
        WaitForPendingJob $sol
    }
    Write-Host -f Green $SolutionWsp deployed $sol.Deployed
    Write-Host -f Green "Activating feature $SolutionWsp at $SiteUrl"   
    Enable-SPFeature -Identity $featureGuid -Url $SiteUrl
}

function RestartTimer
{
    Write-Host -f Green Restarting OWSTIMER instances on Farm
    $farm = Get-SPFarm
    $farm.TimerService.Instances | foreach {$_.Stop();$_.Start();}
}

$date = Get-Date
Write-Host -f Green "Starting upgrade at " $date

Add-PsSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
InstallOrUpdateSolution "Solution1.wsp" $siteUrl "2c6ffaf7-84df-465c-be55-8136926d3e02"
InstallOrUpdateSolution "Solution2.wsp" $siteUrl "0c6be7af-cccd-4ccd-9b61-deffd16f7830"
InstallOrUpdateSolution "Solution3.wsp" $siteUrl "8f4862d3-94ea-467b-bdeb-2352295e08c3"
RestartTimer

$date = Get-Date
Write-Host -f Green "Upgrade finished at" $date

これは一見ランダムなエラーで壊れますが、Visual Studio 2010 からの展開は毎回機能します。Visual Studio のように、コマンド ラインから .wsp を確実にデプロイするにはどうすればよいですか?

4

2 に答える 2

1

なぜretract-delete-install-deployシーケンスの代わりにUpdate-SPSolutionを使用しないのですか?

于 2010-12-13T21:44:45.243 に答える
-1

まず第一に、バッチ ファイルで stsadm の代わりに PowerShell を使用して、展開プロセスを複雑にしすぎているのはなぜですか? PowerShell は必要ですか?

于 2010-10-19T22:01:44.100 に答える