From e4ba6cca1463e967e960da6a2ce11c5204340bb9 Mon Sep 17 00:00:00 2001 From: Dan Caswell Date: Fri, 13 Oct 2017 16:28:17 -0400 Subject: [PATCH] Add feature allowing creation of missing folders on the target. --- .../SqlReportingServicesDeployment.ps1 | 68 ++++++++++++++++++- .../SqlReportingServicesDeployment/task.json | 11 ++- SqlReportingServices/vss-extension.json | 2 +- 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/SqlReportingServices/SqlReportingServicesDeployment/SqlReportingServicesDeployment.ps1 b/SqlReportingServices/SqlReportingServicesDeployment/SqlReportingServicesDeployment.ps1 index c5e62c3..1e47840 100644 --- a/SqlReportingServices/SqlReportingServicesDeployment/SqlReportingServicesDeployment.ps1 +++ b/SqlReportingServices/SqlReportingServicesDeployment/SqlReportingServicesDeployment.ps1 @@ -21,7 +21,8 @@ param( [string]$WsPassword, [string]$UseVerbose, [string]$OverrideExisting, - [string]$AddResourceExtension + [string]$AddResourceExtension, + [string]$CreateMissingFolders ) function Verbose-WriteLine{ [cmdletbinding()] @@ -40,6 +41,43 @@ param( #$Host.UI.RawUI.BackgroundColor = $oldBackColor; } } + + + function Create-MissingFolders{ + [cmdletbinding()] + param( + [Parameter(Position=1)]$uploadRootPath + ) + + $uploadRootPathItem = $ssrs.ListChildren("/", $true) | Where-Object {$_.Path -eq $uploadRootPath -and $_.TypeName -eq "Folder"} + + if($uploadRootPathItem -eq $null) + { + $rootFolder = '/' + + $uploadRootPath.Split('/') | Where-Object {$_.Length -gt 0} | ForEach-Object { + $folderName = $_ + $existingFolder = $ssrs.ListChildren($rootFolder, $true) | Where-Object {$_.TypeName -eq "Folder" -and $_.Name -eq $folderName} + + if($existingFolder -eq $null) + { + Write-Host "Creating $folderName in $rootFolder" + $ssrs.CreateFolder($folderName, $rootFolder, $null) + } + if($rootFolder -eq '/') + { + $rootFolder += $folderName + } + else + { + $rootFolder += "/$folderName" + } + } + } + } + + + ########################################################## # SETUP OF CODE # ########################################################## @@ -134,8 +172,15 @@ param( $rdsFiles = @(Get-ChildItem $DataSourceLocalPath); $rdsFileCount = $rdsFiles.Length; - if($IncludeDataSource -eq $true){ #Update the datasources - Write-Host "Updating $rdsFileCount datasource files to $WebserviceUrl ($ReportUploadRootPath)..."; + if($IncludeDataSource -eq $true){ + + if($CreateMissingFolders -eq $true) + { + Create-MissingFolders $DataSourceRootPath + } + + #Update the datasources + Write-Host "Updating $rdsFileCount datasource files to $WebserviceUrl ($DataSourceRootPath)..."; $rdsFiles | ForEach-Object{ $datasourceName = $_.FullName; Write-Host "Uploading datasource $datasourceName to $DataSourceRootPath..."; @@ -173,6 +218,12 @@ param( $rsdFiles = @(Get-ChildItem $DataSetLocalPath); $rsdFileCount = $rsdFiles.Length; if($IncludeDataSet -eq $true){ + + if($CreateMissingFolders -eq $true) + { + Create-MissingFolders $DataSetRootPath + } + Write-Host "Uploading $rsdFileCount Dataset files"; $rsdFiles | ForEach-Object { $datasetName = $_.FullName; @@ -216,6 +267,12 @@ param( ########################################################## if($IncludeResources -eq $true){ + + if($CreateMissingFolders -eq $true) + { + Create-MissingFolders $ResourceRootPath + } + Add-Type -AssemblyName "System.Web"; ForEach($item in @($ResourcePatterns.Split("`n"))){ Write-Warning $item; @@ -272,6 +329,11 @@ param( $fileCount = $files.Length; Verbose-WriteLine "Found $fileCount items in $ReportFiles"; + if($CreateMissingFolders -eq $true) + { + Create-MissingFolders $ReportUploadRootPath + } + Write-Host "Uploading $fileCount files to $WebserviceUrl ($ReportUploadRootPath)..."; #Itterate over all files and append them to a catalogitem $files | ForEach-Object{ diff --git a/SqlReportingServices/SqlReportingServicesDeployment/task.json b/SqlReportingServices/SqlReportingServicesDeployment/task.json index 5a64db1..bcc0503 100644 --- a/SqlReportingServices/SqlReportingServicesDeployment/task.json +++ b/SqlReportingServices/SqlReportingServicesDeployment/task.json @@ -27,7 +27,7 @@ "version": { "Major": "1", "Minor": "4", - "Patch": "3" + "Patch": "4" }, "minimumAgentVersion": "1.95.0", "instanceNameFormat": "Deploy SQL Server reporting files", @@ -228,6 +228,15 @@ "defaultValue": false, "groupName": "advanced", "helpMarkDown": "Enable or disable verbose logging" + }, + { + "name": "CreateMissingFolders", + "type": "boolean", + "label": "Create Missing Folders", + "required": false, + "defaultValue": false, + "groupName": "advanced", + "helpMarkDown": "Enable or disable creation of missing folders on the target" } ], diff --git a/SqlReportingServices/vss-extension.json b/SqlReportingServices/vss-extension.json index cf515c7..e9e73e1 100644 --- a/SqlReportingServices/vss-extension.json +++ b/SqlReportingServices/vss-extension.json @@ -2,7 +2,7 @@ "manifestVersion": 1, "id": "SqlReportngServices", "name": "SQL Server Reporting Services Deployment", - "version": "1.5.3", + "version": "1.5.4", "publisher": "tobania", "targets": [ {