-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-sitecorepackage.ps1
87 lines (76 loc) · 2.63 KB
/
deploy-sitecorepackage.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<#
This function uploads & installs the specified Sitecore update package to the given $SiteUrl.
Example usage:
.\deploy-sitecorepackage.ps1 mysite.dev "C:\Project\Build\Artifacts\1-mysite-templates.update" 300 MyUsername MyPassword
.\deploy-sitecorepackage.ps1 mysite.dev "C:\Project\Build\Artifacts\1-mysite-templates.update" 300 -ResultsOutputPath "c:\temp\ids.txt"
#>
Param(
[Parameter(Position=0, Mandatory=$true)]
[string]$SiteUrl,
[Parameter(Position=1, Mandatory=$true)]
[string]$UpdatePackagePath,
[Parameter(Position=2)]
[ValidateRange(0, 99999)]
[int]$ConnectionTimeOutInSeconds = 300,
[Parameter(Position=3)]
[string]$Username,
[Parameter(Position=4)]
[string]$Password,
[Parameter(Position=5)]
[string]$ResultsOutputPath
)
Write-Host "Creating new WebClientEx type"
Add-Type @"
using System;
using System.Net;
public class WebClientWithTimeout : WebClient
{
public int TimeoutSeconds {get; set;}
protected override WebRequest GetWebRequest(Uri address)
{
var request = base.GetWebRequest(address);
request.Timeout = TimeoutSeconds * 1000;
return request;
}
}
"@
Write-Host "SiteUrl:" $SiteUrl
Write-Host "UpdatePackagePath:" $UpdatePackagePath " - Exists:" (Test-Path $UpdatePackagePath) " - IsDir:" ((Get-Item $UpdatePackagePath) -is [System.IO.DirectoryInfo])
Write-Host "ConnectionTimeOutInSeconds:" $ConnectionTimeOutInSeconds
Write-Host "Username:" $Username
Write-Host "Password:" $Password
Write-Host "ResultsOutputPath:" $ResultsOutputPath
$fileUploadUrl = "$SiteUrl/services/package/install/fileupload"
$shipHtml = ""
$item = Get-Item $UpdatePackagePath
$webclient = New-Object WebClientWithTimeout
$webclient.TimeoutSeconds = $ConnectionTimeOutInSeconds
if($Username){
$webclient.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
}
$uri = New-Object System.Uri($fileUploadUrl)
$rawResponse = $webclient.UploadFile($uri, $item.FullName)
$shipHtml = [System.Text.Encoding]::ASCII.GetString($rawResponse)
if($shipHtml -eq $null)
{
Write-Host "Empty response from ship..."
}
if($shipHtml -ne $null)
{
$shipResponse = $shipHtml | ConvertFrom-Json
$shipEntries = $shipResponse.Entries
$items = New-Object System.Collections.Generic.List[string]
$shipEntries |
ForEach-Object {
if($_.ID -ne $null)
{
Write-Host $_.ID -foregroundcolor cyan
$items.Add($_.ID )
}
}
if((-not [string]::IsNullOrEmpty($ResultsOutputPath)))
{
Write-Host "Saving Results to:" $ResultsOutputPath
$items | out-file $ResultsOutputPath
}
}