HodorNV / ALOps

ALOps
59 stars 24 forks source link

Support for new SchemaSyncMode "Force Sync" for Uploading PTE Extensions [BC21.2] #590

Closed pri-kise closed 1 year ago

pri-kise commented 1 year ago

Is your feature request related to a problem? Please describe. Could you please provide support for uploading PTE Extension with ForceSync.

We could discuss how this property should work on batch publish.

Describe the solution you'd like a new Boolean flag that we could set manually for specific releases.

Describe alternatives you've considered Currently we're manually uploading extensions in case of breaking changes.

Additional context Here is an example copied from the thread on Yammer. (https://www.yammer.com/dynamicsnavdev/threads/2014045471588352)

function Install-PTEApp {

    [CmdletBinding()]

    param 

    (

        [parameter(Mandatory = $true, ValueFromPipeline = $true)]  

        $Environment,

        [parameter(Mandatory = $true)]  

        [string] $AppFile,

        [Parameter(Mandatory = $false)]

        [ValidateSet('Current version', 'Next minor version', 'Next major version')]

        [string] $Schedule = 'Current version',

        [Parameter(Mandatory = $false)]

        [ValidateSet('Add', 'Force Sync')]

        [string] $Mode = 'Add',

        [parameter(Mandatory = $false)]

        [switch] $Wait

    )

    process {

        $Company = $Environment | Get-Companies | Select-Object -First 1 

        $ExtensionUpload = (Invoke-RestMethod -Uri "$($Environment.webServiceUrl)/$(Get-AutomationApi)/companies($($Company.id))/extensionUpload" -Headers (Get-BcApiHeaders -AadTenantId $Environment.AadTenantId)).value

        if ($null -eq $ExtensionUpload.systemId) {

            $Body = @{

                schedule = $Schedule

                schemaSyncMode = $Mode

            }

            $ExtensionUpload = Invoke-RestMethod -Uri "$($Environment.webServiceUrl)/$(Get-AutomationApi)/companies($($Company.id))/extensionUpload" -Headers (Get-BcApiHeaders -AadTenantId $Environment.AadTenantId) -Method Post -Body ($Body | ConvertTo-Json)

        }

        if ($null -ne $ExtensionUpload.systemId) {

            $Body = (Invoke-WebRequest $AppFile).Content

            Invoke-RestMethod -Uri $ExtensionUpload.'extensionContent@odata.mediaEditLink' -Headers (Get-BcApiHeaders -AadTenantId $Environment.AadTenantId -IfMatch '*' -ContentType 'application/octet-stream') -Method Patch -Body $Body | Out-Null

            Invoke-RestMethod -Uri "$($Environment.webServiceUrl)/$(Get-AutomationApi)/companies($($Company.id))/extensionUpload($($ExtensionUpload.systemId))/Microsoft.NAV.upload" -Headers (Get-BcApiHeaders -AadTenantId $Environment.AadTenantId -IfMatch '*') -Method Post | Out-Null

            if ($Wait) {

                $Activity = "Installing PTE App '$AppFile'"

                do {

                    Start-Sleep 5

                    $extensionDeploymentStatus = (Invoke-RestMethod -Uri "$($Environment.webServiceUrl)/$(Get-AutomationApi)/companies($($Company.id))/extensionDeploymentStatus" -Headers (Get-BcApiHeaders -AadTenantId $Environment.AadTenantId)).Value | Select-Object -First 1

                    Write-Progress -Activity $Activity -Status $extensionDeploymentStatus.status

                } while ($extensionDeploymentStatus.status -in @('InProgress'))

                Write-Progress -Activity $Activity -Status 'Completed' -Completed

                if ($extensionDeploymentStatus.status -eq 'Failed') {

                    Write-Host "Install PTE App '$AppFile' Failed!" -ForegroundColor Red

                    $Environment | Start-Environment -Querystring 'page=2508'

                }

            }

        }

    }

}
pri-kise commented 1 year ago

BCContainerHelper for Reference: https://github.com/microsoft/navcontainerhelper/blob/master/SaaS/Publish-PerTenantExtensionApps.ps1

waldo1001 commented 1 year ago

The step AlopsAppPublish does have a ForceSync parameter.

Isn't that what you mean?

pri-kise commented 1 year ago

I must have missed this setting.