Testing/Install-BuildHelper.ps1

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','BC14','BC15')]
        $BuildHelperVersion = 'Detect'
    )

    if ($BuildHelperVersion -eq 'Detect') {
        [Version]$PlatformVersion = [Version]::Parse((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'platform'))
        if ($PlatformVersion -ge ([Version]::Parse('15.0.0.0'))) {
            $BuildHelperVersion = 'BC15'
        }
        else {
            $BuildHelperVersion = 'BC14'
        }
    }
    
    $Install = $false

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

    if ($Install) {        
        $DestinationFile = Join-Path (New-TempDirectory) 'NavBuildHelper.app'
        switch ($BuildHelperVersion) {
            'BC14' { $SourceURL = 'https://navxdev.blob.core.windows.net/files/NAV-X_NAV-X%20Build%20Helper_1.0.0.0_BC14.app' }
            'BC15' { $SourceURL = 'https://navxdev.blob.core.windows.net/files/NAV-X_NAV-X%20Build%20Helper_1.0.0.0.app' }
        }

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

Export-ModuleMember -Function Install-BuildHelper