SharePoint Solution Deployment
Octopus.Script exported 10/09/2015 by jasmin-mistry belongs to 'SharePoint' category.
SharePoint Solution Deployment for 2010 & 2013.
Parameters
When steps based on the template are included in a project's deployment process, the parameters below can be set.
SharePoint Solution Package Step
NugetPackageStepName
Select the step in this project which downloads the SharePoint package.
Script body
Steps based on this template will execute the following PowerShell script.
Show script$DeployedPath = $OctopusParameters["Octopus.Action[$NugetPackageStepName].Output.Package.InstallationDirectoryPath"]
$ReleaseNumber = $OctopusParameters["Octopus.Release.Number"]
Write-Host "Deploy Path: $DeployedPath"
Write-Host "Release Number: $ReleaseNumber"
function Deploy-SPSolution($wsp) {
$wspName = $wsp.SubString($wsp.LastIndexOf("\") + 1)
$solution = Get-SPSolution -Identity $wspName -ErrorAction silentlycontinue
if ($solution -ne $null)
{
Write-Output "'$wspName' solution already installed - removing solution"
# need to take a back up of this wsp before uninstalling it.
if($solution.ContainsWebApplicationResource) {
$solution | Uninstall-SPSolution -AllWebApplications -Confirm:$false
}
else {
$solution | Uninstall-SPSolution -Confirm:$false
}
while ($solution.JobExists) {
Start-Sleep 30
}
Write-Output "$wspName has been uninstalled successfully."
Write-Output "Removing '$wspName' solution from farm"
$solution | Remove-SPSolution -Force -Confirm:$false
# now install
Write-Output "Installing solution '$wspName'"
Add-SPSolution -LiteralPath "$wsp" | Out-Null
Write-Output "$wsp solution added sucessfully"
if(($solution -ne $null) -and ($solution.ContainsWebApplicationResource)) {
Install-SPSolution -Identity $wspName –AllwebApplications -GACDeployment -Force -Confirm:$false
}
else {
Install-SPSolution -Identity $wspName -GACDeployment -Force -Confirm:$false
}
<#
while ($Solution.Deployed -eq $false) {
Start-Sleep 30
}
#>
}
else {
Write-Output "Installing solution '$wspName'"
Add-SPSolution -LiteralPath "$wsp" -ErrorAction Stop
Install-SPSolution -Identity $wspName -GACDeployment -Force -ErrorAction Stop
}
}
function Start-AdminService() {
$AdminServiceName = "SPAdminV4"
if ($(Get-Service $AdminServiceName).Status -eq "Stopped") {
Start-Service $AdminServiceName
Write-Host "$AdminServiceName service was not running, now started."
return $false;
}
return $true
}
function Stop-AdminService($IsAdminServiceWasRunning) {
$AdminServiceName = "SPAdminV4"
if ($IsAdminServiceWasRunning -eq $false ) {
Stop-Service $AdminServiceName
}
}
#region Main
try
{
# add powershell snap in for sharepoint functions
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
}
#Admin service
$IsAdminServiceWasRunning = $true;
$IsAdminServiceWasRunning = Start-AdminService
$wspFiles = @()
# get all report files for deployment
Write-Host "Getting all .wsp files"
Get-ChildItem $DeployedPath -Recurse -Filter "*.wsp" | ForEach-Object { If(($wspFiles -contains $_.FullName) -eq $false) {$wspFiles += $_.FullName}}
Write-Host "# of wsp files found: $($wspFiles.Count)"
# loop through array
foreach($wsp in $wspFiles) {
Deploy-SPSolution $wsp
}
Stop-AdminService $IsAdminServiceWasRunning
#Remove SharePoint Snapin
Remove-PsSnapin Microsoft.SharePoint.PowerShell
}
finally
{
}
#endregionTo use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
Show JSON{
"Id": "7ac03a43-cb18-4e83-a114-b158a2bb2a52",
"Name": "SharePoint Solution Deployment",
"Description": "SharePoint Solution Deployment for 2010 & 2013.",
"Version": 1,
"ExportedAt": "2015-10-09T16:20:24.330+00:00",
"ActionType": "Octopus.Script",
"Author": "jasmin-mistry",
"Parameters": [
{
"Name": "NugetPackageStepName",
"Label": "SharePoint Solution Package Step",
"HelpText": "Select the step in this project which downloads the SharePoint package.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "StepName"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "$DeployedPath = $OctopusParameters[\"Octopus.Action[$NugetPackageStepName].Output.Package.InstallationDirectoryPath\"]\n$ReleaseNumber = $OctopusParameters[\"Octopus.Release.Number\"]\n\nWrite-Host \"Deploy Path: $DeployedPath\"\nWrite-Host \"Release Number: $ReleaseNumber\"\n\nfunction Deploy-SPSolution($wsp) {\n\n\t$wspName = $wsp.SubString($wsp.LastIndexOf(\"\\\") + 1)\n\n\t$solution = Get-SPSolution -Identity $wspName -ErrorAction silentlycontinue\n\n\tif ($solution -ne $null) \n\t{ \n\t Write-Output \"'$wspName' solution already installed - removing solution\"\n\t\t\n\t\t# need to take a back up of this wsp before uninstalling it.\t\t\n\t\tif($solution.ContainsWebApplicationResource) {\n\t $solution | Uninstall-SPSolution -AllWebApplications -Confirm:$false\n\t }\n\t else {\n\t $solution | Uninstall-SPSolution -Confirm:$false\n\t }\n\t\t\n\t\twhile ($solution.JobExists) {\n\t\t Start-Sleep 30\n\t\t}\n\t\t\n\t\tWrite-Output \"$wspName has been uninstalled successfully.\"\n\n\t Write-Output \"Removing '$wspName' solution from farm\" \n\t $solution | Remove-SPSolution -Force -Confirm:$false \n\t\n\t\t# now install \n\t\tWrite-Output \"Installing solution '$wspName'\" \n\t\tAdd-SPSolution -LiteralPath \"$wsp\" | Out-Null\n\t\t\n\t\tWrite-Output \"$wsp solution added sucessfully\"\n\t\tif(($solution -ne $null) -and ($solution.ContainsWebApplicationResource)) {\n\t\t\tInstall-SPSolution -Identity $wspName –AllwebApplications -GACDeployment -Force -Confirm:$false\n\t\t}\n\t\telse {\n\t\t\tInstall-SPSolution -Identity $wspName -GACDeployment -Force -Confirm:$false\n\t\t}\n\n\t\t<#\n\t\twhile ($Solution.Deployed -eq $false) {\n\t\t Start-Sleep 30\n\t\t}\n\t\t#>\n\t}\n\telse {\n\t\tWrite-Output \"Installing solution '$wspName'\" \n\t\tAdd-SPSolution -LiteralPath \"$wsp\" -ErrorAction Stop\n\t\tInstall-SPSolution -Identity $wspName -GACDeployment -Force -ErrorAction Stop\n\t}\n}\n\nfunction Start-AdminService() {\n\t$AdminServiceName = \"SPAdminV4\"\n\t\n\tif ($(Get-Service $AdminServiceName).Status -eq \"Stopped\") {\n\t Start-Service $AdminServiceName\n\t \tWrite-Host \"$AdminServiceName service was not running, now started.\"\n\t\treturn $false;\n\t}\n\t\n\treturn $true\n}\n\nfunction Stop-AdminService($IsAdminServiceWasRunning) {\n\t$AdminServiceName = \"SPAdminV4\"\t\n\tif ($IsAdminServiceWasRunning -eq $false ) { \n\t\tStop-Service $AdminServiceName\t\n\t}\n}\n\n#region Main\ntry\n{\n\t# add powershell snap in for sharepoint functions\n\tif ((Get-PSSnapin \"Microsoft.SharePoint.PowerShell\" -ErrorAction SilentlyContinue) -eq $null) { \n\t Add-PSSnapin \"Microsoft.SharePoint.PowerShell\" -ErrorAction SilentlyContinue\n\t}\n\t\n\t#Admin service\n\t$IsAdminServiceWasRunning = $true;\n\t\n\t$IsAdminServiceWasRunning = Start-AdminService\n\t\n\t$wspFiles = @()\n\t\n\t# get all report files for deployment\n Write-Host \"Getting all .wsp files\"\n Get-ChildItem $DeployedPath -Recurse -Filter \"*.wsp\" | ForEach-Object { If(($wspFiles -contains $_.FullName) -eq $false) {$wspFiles += $_.FullName}}\n Write-Host \"# of wsp files found: $($wspFiles.Count)\"\n\t\n\t# loop through array\n foreach($wsp in $wspFiles) {\n\t\tDeploy-SPSolution $wsp\n\t}\t\n\t\n\tStop-AdminService $IsAdminServiceWasRunning\n\t\n\t#Remove SharePoint Snapin\n\tRemove-PsSnapin Microsoft.SharePoint.PowerShell\n}\nfinally\n{\n \n}\n\n#endregion",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"Category": "SharePoint",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates/sharepoint-solution-deployment.json",
"Website": "/step-templates/7ac03a43-cb18-4e83-a114-b158a2bb2a52",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////I3K6yNzuWpXLkbjcMXu+8fb74+321uTydqfUP4TDTI3HrMrlaJ7QhLDY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AQDQjUuDScYztgAAAABJRU5ErkJggg==",
"$Meta": {
"Type": "ActionTemplate"
}
}Provided under the Apache License version 2.0.