|
$ErrorActionPreference = "Stop" |
|
|
|
$deploypath = Split-Path $MyInvocation.MyCommand.Path |
|
if ($OctopusDeploymentId) { |
|
$deploypath = $OctopusParameters["OctopusOriginalPackageDirectoryPath"] |
|
} |
|
|
|
[Reflection.Assembly]::LoadFrom("$deploypath\Microsoft.WindowsAzure.Storage.dll") | Out-Null |
|
[Reflection.Assembly]::LoadFrom("$deploypath\Microsoft.Data.Services.Client.dll") | Out-Null |
|
|
|
function Create-PublicBlobContainer($storageAccount, $containerName) { |
|
$blobClient = $storageAccount.CreateCloudBlobClient() |
|
$container = $blobClient.GetContainerReference($containerName) |
|
$container.CreateIfNotExists() | Out-Null |
|
$permissions = New-Object -TypeName "Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions" |
|
$permissions.PublicAccess = [Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType]::Blob |
|
$container.SetPermissions($permissions) |
|
return $container |
|
} |
|
|
|
function Upload-Blob($container, $file) { |
|
$blob = $container.GetBlockBlobReference("$($file.BaseName)$($file.Extension)") |
|
$blob.UploadFromFile($file.FullName, [System.IO.FileMode]::Open) |
|
if ($file.Extension -eq ".html") { |
|
$blob.Properties.ContentType = "text/html" |
|
} |
|
if ($file.Extension -eq ".png") { |
|
$blob.Properties.ContentType = "image/png" |
|
} |
|
if ($file.Extension -eq ".ipa") { |
|
$blob.Properties.ContentType = "application/x-itunes-ipa" |
|
} |
|
if ($file.Extension -eq ".plist") { |
|
$blob.Properties.ContentType = "binary/octet-stream" |
|
} |
|
$blob.SetProperties() |
|
} |
|
|
|
$appID = "{PGB_APP_ID_LOCAL_TESTING}" |
|
$apiKey = "{PGB_API_KEY_LOCAL_TESTING}" |
|
$zipFile = "app.zip" |
|
$iosOverTheAirKey = "{PGB_IOS_OVER_THE_AIR_KEY_NAME_LOCAL_TESTING}" |
|
$iosOverTheAirKeyPassword = "{PGB_IOS_OVER_THE_AIR_KEY_PASSWORD_LOCAL_TESTING}" |
|
$iosKey = "{PGB_IOS_PRODUCTION_KEY_NAME_LOCAL_TESTING}" |
|
$iosKeyPassword = "{PGB_IOS_PRODUCTION_KEY_PASSWORD_LOCAL_TESTING}" |
|
$androidKey = "{PGB_ANDROID_PRODUCTION_KEY_NAME_LOCAL_TESTING}" |
|
$androidKeyPassword = "{PGB_ANDROID_PRODUCTION_KEY_PASSWORD_LOCAL_TESTING}" |
|
$version = 1,0,0,0 |
|
$storageAccount = [Microsoft.WindowsAzure.Storage.CloudStorageAccount]::DevelopmentStorageAccount |
|
$warningsAllowed = $true |
|
|
|
if ($OctopusDeploymentId) { |
|
$appID = $OctopusParameters["PhoneGapBuildAppId"] |
|
$apiKey = $OctopusParameters["PhoneGapBuildApiKey"] |
|
$zipFile = "app.zip" |
|
$iosOverTheAirKey = $OctopusParameters["PhoneGapBuildIosOverTheAirKey"] |
|
$iosOverTheAirKeyPassword = $OctopusParameters["PhoneGapBuildIosOverTheAirKeyPassword"] |
|
$iosKey = $OctopusParameters["PhoneGapBuildIosKey"] |
|
$iosKeyPassword = $OctopusParameters["PhoneGapBuildIosKeyPassword"] |
|
$androidKey = $OctopusParameters["PhoneGapBuildAndroidKey"] |
|
$androidKeyPassword = $OctopusParameters["PhoneGapBuildAndroidKeyPassword"] |
|
$version = $OctopusParameters["Octopus.Release.Number"].split(".") |
|
$storageConnectionString = $OctopusParameters["IosOverTheAirStorageAccount"] |
|
$storageAccount = [Microsoft.WindowsAzure.Storage.CloudStorageAccount]::Parse($storageConnectionString) |
|
$warningsAllowed = $false |
|
} |
|
|
|
try |
|
{ |
|
Write-Output "Deploying to PhoneGapBuild" |
|
if (Test-Path .\node\node.exe) { |
|
.\node\node node\pgb.js --appId $appID --apiKey $apiKey --zipFile $zipFile --iosOverTheAirKey $iosOverTheAirKey --iosOverTheAirKeyPassword $iosOverTheAirKeyPassword --iosKey $iosKey --iosKeyPassword $iosKeyPassword --androidKey $androidKey --androidKeyPassword $androidKeyPassword |
|
if ($LastExitCode -ne 0) { |
|
throw "Non-zero exit code from pgb.js" |
|
} |
|
} elseif ($warningsAllowed) { |
|
Write-Warning "node not found; can't deploy to PGB" |
|
} else { |
|
throw "node not found; can't deploy to PGB" |
|
} |
|
|
|
Write-Output "Stage the .ipa file" |
|
if (Test-Path .\build.ipa) { |
|
mv .\build.ipa .\overtheair\app.ipa -Force |
|
} elseif ($warningsAllowed) { |
|
Write-Warning "build.ipa not found" |
|
} else { |
|
throw "build.ipa not found" |
|
} |
|
|
|
Write-Output "Uploading files to blob storage" |
|
$container = Create-PublicBlobContainer $storageAccount "app" |
|
(Get-Content $deploypath\overtheair\app.plist) -Replace "1.0.0","$($version[0]).$($version[1]).$($version[2])" | Set-Content $deploypath\overtheair\app.plist |
|
ls -File $deploypath\overtheair | Foreach-Object { |
|
Upload-Blob $container $_ |
|
Write-Output "Uploaded $_" |
|
} |
|
} |
|
catch |
|
{ |
|
$Host.UI.WriteErrorLine($_) |
|
exit 1 |
|
} |