Testing/Install-BuildHelper.ps1

<#
.synopsis
    Installs the NAV-X Build Helper into a container
.description
    The NAV-X Build Helper is used to generate test suites. It will be replaced with new functionality. Do not use in new development
.parameter ContainerName
    Container to be used. Can be provided in the settings.json
.parameter Reinstall
    Add this switch to reinstall the app when already existing
.parameter BuildHelperVersion
    Version of NAV/BC to use. You can use "Detect" to let the system determine the version
.example
    Install-BuildHelper -ContainerName test -Reinstall
#>

function Install-BuildHelper {
    param (
        # Container name to install the Build Helper into
        [Parameter(Mandatory = $false)]
        [string]
        $ContainerName = (Get-ContainerFromLaunchJson),
        # Whether to force a reinstall of the app
        [Parameter(Mandatory = $false)]
        [switch]
        $Reinstall,
        # Version of the build helper app to install, use BC15 if not specified
        [Parameter(Mandatory = $false)]
        [string]
        [ValidateSet('Detect', 'NAV2018', 'BC13', 'BC14', 'Modern')]
        $BuildHelperVersion = 'Detect'
    )

    if ($BuildHelperVersion -eq 'Detect') {
        [Version]$PlatformVersion = [Version]::Parse((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'platform'))
        if ($PlatformVersion.Major -ge 15){
            $BuildHelperVersion = 'Modern';
        }
        else {
            switch ($PlatformVersion.Major) {
                11 {
                    $BuildHelperVersion = 'NAV2018'
                    break
                }
                13 {
                    $BuildHelperVersion = 'BC13'
                    break
                }
                14 {
                    $BuildHelperVersion = 'BC14'
                    break
                }
            }
        }
    }

    $Install = $false

    if ($Reinstall.IsPresent) {
        $Install = $true
    }
    else {
        #test for the existence of the build helper service
        try {
            switch ($BuildHelperVersion) {
                'NAV2018' {
                    $Uri = 'http://{0}:7047/NAV/WS/Codeunit/NavxAutomatedTestManagement' -f (Get-BcContainerIpAddress $ContainerName)
                    break
                }
                'BC13' {
                    $Uri = 'http://{0}:7047/NAV/WS/Codeunit/NavxAutomatedTestManagement' -f (Get-BcContainerIpAddress $ContainerName)
                    break
                }
                'BC14' {
                    $Uri = 'http://{0}:7047/NAV/WS/Codeunit/NavxAutomatedTestManagement' -f (Get-BcContainerIpAddress $ContainerName)
                    break
                }
                'Modern' {
                    $Uri = 'http://{0}:7047/BC/WS/Codeunit/NavxAutomatedTestManagement' -f (Get-BcContainerIpAddress $ContainerName)
                    break
                }
            }
            Invoke-WebRequest $Uri -Credential (Get-CredentialFromEnvironmentJson)
        }
        catch {
            $Install = $true
        }
    }

    if ($Install) {
        $DestinationFile = Join-Path (New-TempDirectory) 'NavBuildHelper.app'
        switch ($BuildHelperVersion) {
            'NAV2018' {
                $SourceURL = 'https://navxdev.blob.core.windows.net/files/NAV-X_NAV-X%20Build%20Helper_1.0.0.0_NAV2018.app?sv=2019-10-10&st=2020-09-25T17%3A53%3A13Z&se=2023-09-24T17%3A53%3A00Z&sr=b&sp=r&sig=v%2F3GIqlpAtOt2gk01WSp2z0oT3RIYvAqV8kl8pw0FU4%3D'
                break
            }
            'BC13' {
                $SourceURL = 'https://navxdev.blob.core.windows.net/files/NAV-X_NAV-X%20Build%20Helper_1.0.0.0_BC13.app?sv=2019-10-10&st=2020-09-25T17%3A54%3A01Z&se=2023-09-24T17%3A54%3A00Z&sr=b&sp=r&sig=r%2BvXW3GuRvy1lfmMdMxBZ1m%2BKT9XPH3IO%2FTc2z7Vwgs%3D'
                break
            }
            'BC14' {
                $SourceURL = 'https://navxdev.blob.core.windows.net/files/NAV-X_NAV-X%20Build%20Helper_1.0.0.0_BC14.app?sv=2019-10-10&st=2020-09-25T17%3A54%3A28Z&se=2023-09-24T17%3A54%3A00Z&sr=b&sp=r&sig=11UrOnaILVaHXkEusKdRA28x3hB47V2k%2B1RBbnD2RXU%3D'
                break
            }
            'Modern' {
                $SourceURL = 'https://navxdev.blob.core.windows.net/files/NAV-X_NAV-X%20Build%20Helper_1.0.0.0.app?sv=2019-10-10&st=2020-09-25T17%3A54%3A49Z&se=2023-09-24T17%3A54%3A00Z&sr=b&sp=r&sig=4eepf%2BXgMew4JWyYGGzgHb7%2Bj3tyamwqOMSf32rduy8%3D'
                break
            }
        }

        Download-File -sourceUrl $SourceURL -destinationFile $DestinationFile
        Publish-BcContainerApp -containerName $ContainerName -appFile $DestinationFile -install -sync
    }
}

Export-ModuleMember -Function Install-BuildHelper