Functions/AzDevOps/Export-CdsSolutionsBuild.ps1
<#
.SYNOPSIS Run build action to export solutions #> function Export-CdsSolutionsBuild { [CmdletBinding()] param ( [Parameter(Mandatory = $false)] [String] $ConnectionString = $env:CONNECTIONSTRING, [Parameter(Mandatory = $false)] [String] $ExportPath = $env:BUILD_ARTIFACTSTAGINGDIRECTORY, [Parameter(Mandatory = $false)] [String] $Solutions = $env:SOLUTIONS, [Parameter(Mandatory = $false)] [Boolean] $Managed = $true, [Parameter(Mandatory = $false)] [Boolean] $ExportCalendarSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportCustomizationSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportEmailTrackingSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportAutoNumberingSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportIsvConfig = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportOutlookSynchronizationSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportGeneralSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportMarketingSettings = $false, [Parameter(Mandatory = $false)] [Boolean] $ExportRelationshipRoles = $false ) begin { $StopWatch = [System.Diagnostics.Stopwatch]::StartNew(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Start -Parameters ($MyInvocation.MyCommand.Parameters); } process { $cdsClient = New-CdsClient -ConnectionString $ConnectionString -MaxCrmConnectionTimeOutMinutes 15; Write-HostAndLog -Message " - Param : Export path = $ExportPath" -Level INFO; Write-HostAndLog -Message " - Param : Managed = $Managed" -Level INFO; Write-HostAndLog -Message " - Param : Solutions = $Solutions" -Level INFO; Write-HostAndLog -Message " - Param : ExportCalendarSettings = $ExportCalendarSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportCustomizationSettings = $ExportCustomizationSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportEmailTrackingSettings = $ExportEmailTrackingSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportAutoNumberingSettings = $ExportAutoNumberingSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportIsvConfig = $ExportIsvConfig" -Level INFO; Write-HostAndLog -Message " - Param : ExportOutlookSynchronizationSettings = $ExportOutlookSynchronizationSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportGeneralSettings = $ExportGeneralSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportMarketingSettings = $ExportMarketingSettings" -Level INFO; Write-HostAndLog -Message " - Param : ExportRelationshipRoles = $ExportRelationshipRoles" -Level INFO; $solutionList = $Solutions.Split(","); $solutionList | ForEach-Object { Write-HostAndLog -Message "Exporting solution $($_)" -Level INFO; try { $solutionFilePath = $cdsClient | Export-CdsSolution -SolutionUniqueName $_ -Managed $Managed -ExportPath $ExportPath -ExportCalendarSettings $ExportCalendarSettings -ExportCustomizationSettings $ExportCustomizationSettings -ExportEmailTrackingSettings $ExportEmailTrackingSettings -ExportAutoNumberingSettings $ExportAutoNumberingSettings -ExportIsvConfig $ExportIsvConfig -ExportOutlookSynchronizationSettings $ExportOutlookSynchronizationSettings -ExportGeneralSettings $ExportGeneralSettings -ExportMarketingSettings $ExportMarketingSettings -ExportRelationshipRoles $ExportRelationshipRoles; } catch { if($_.Exception.Message.Contains("The underlying connection was closed")) { # Retry if operation timeout is reached (oAuth issue) $solutionFilePath = $cdsClient | Export-CdsSolution -SolutionUniqueName $_ -Managed $Managed -ExportPath $ExportPath -ExportCalendarSettings $ExportCalendarSettings -ExportCustomizationSettings $ExportCustomizationSettings -ExportEmailTrackingSettings $ExportEmailTrackingSettings -ExportAutoNumberingSettings $ExportAutoNumberingSettings -ExportIsvConfig $ExportIsvConfig -ExportOutlookSynchronizationSettings $ExportOutlookSynchronizationSettings -ExportGeneralSettings $ExportGeneralSettings -ExportMarketingSettings $ExportMarketingSettings -ExportRelationshipRoles $ExportRelationshipRoles; } else { throw; } } Write-HostAndLog -Message "Solution $($_) successfully exported to '$solutionFilePath' !" -Level SUCCESS; } } end { $StopWatch.Stop(); Trace-CdsFunction -Name $MyInvocation.MyCommand.Name -Stage Stop -StopWatch $StopWatch; } } Export-ModuleMember -Function Export-CdsSolutionsBuild -Alias *; |