Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish-BCContainerApp on environment fails after upgrade to BC24 #3498

Closed
dsaveyn opened this issue Apr 23, 2024 · 13 comments
Closed

Publish-BCContainerApp on environment fails after upgrade to BC24 #3498

dsaveyn opened this issue Apr 23, 2024 · 13 comments

Comments

@dsaveyn
Copy link

dsaveyn commented Apr 23, 2024

PLEASE DO NOT INCLUDE ANY PASSWORDS OR TOKENS IN YOUR ISSUE!!!

Describe the issue
Yesterday we upgraded our test environment to BC24. We have setup a pipeline in devops that uses Publish-BCContainerApp to update the environment with our latest apps from our build pipelines. Since the upgrade the install of every app fails with the following error message:

2024-04-23T08:16:17.9456818Z Installing Apps
2024-04-23T08:16:19.9499400Z Publishing Dynavision_Dynavision Advanced Finance_23.0.8.18655_sandbox_23.1_w1.app to https://api.businesscentral.dynamics.com/v2.0/DynavisionTest/dev/apps?SchemaUpdateMode=forcesync&DependencyPublishingOption=default
2024-04-23T08:16:36.9244284Z Status Code 422 : Unprocessable Entity
2024-04-23T08:16:36.9244892Z Er is geen gepubliceerde extensie die overeenkomt met de opgegeven parameterwaarden.
2024-04-23T08:16:36.9245146Z 
2024-04-23T08:16:37.3597442Z Publish-BcContainerApp Telemetry Correlation Id: 5fc028b7-d7bd-4fc0-b6e0-6c6fe6f5ba00
2024-04-23T08:16:37.3965657Z Status Code 422 : Unprocessable Entity
2024-04-23T08:16:37.3966209Z Er is geen gepubliceerde extensie die overeenkomt met de opgegeven parameterwaarden.
2024-04-23T08:16:37.3967137Z At C:\Program Files\WindowsPowerShell\Modules\BCContainerHelper\6.0.15\AppHandling\Publish-NavContainerApp.ps1:295 
2024-04-23T08:16:37.3967783Z char:25
2024-04-23T08:16:37.3968019Z +                         throw $message
2024-04-23T08:16:37.3968271Z +                         ~~~~~~~~~~~~~~
2024-04-23T08:16:37.3968590Z     + CategoryInfo          : OperationStopped: (Status Code 422...meterwaarden.
2024-04-23T08:16:37.3969194Z :String) [], RuntimeException
2024-04-23T08:16:37.3969940Z     + FullyQualifiedErrorId : Status Code 422 : Unprocessable Entity
2024-04-23T08:16:37.3970535Z Er is geen gepubliceerde extensie die overeenkomt met de opgegeven parameterwaarden.
2024-04-23T08:16:37.3971094Z  
2024-04-23T08:16:37.4673773Z ##[error]PowerShell exited with code '1'.

Scripts used to create container and cause the issue

# Create temporary directory
$TempDirectoryName = [System.IO.Path]::Combine($env:TEMP, [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $TempDirectoryName -Force | Out-Null

Write-Host "The following Apps will be published:"
(Get-ChildItem -Path $AppFolder -Filter '*.app' -Recurse) | % {
    Write-Host "$($_.Name) (found in directory '$($_.Directory)')"     
    Copy-Item -Path $_.FullName -Destination $TempDirectoryName
}
   
Write-Host "Installing Apps"
Publish-BcContainerApp `
    -bcAuthContext $AuthContext `
    -environment $Environment `
    -appFile $TempDirectoryName `
    -dependencyPublishingOption default `
    -syncMode ForceSync 

# Remove temporary directory
Remove-Item $TempDirectoryName -Recurse

Full output of scripts
See above

Screenshots
N/A

Additional context
BCContainerHelper fails when executing the API call to BC:

image

When I inspect the environment after the error, I notice the app is published but not installed. So it appears the install fails. I also noticed it takes a while for the published app the show up in extension management. It seems there's a delay that might cause this error.

On BC23 the update of our test environment was already quite slow (we have 27 apps to publish) but It worked. The environment has quite some companies.

@freddydk
Copy link
Contributor

Does the extension management page reveal what the problem is?

@dsaveyn
Copy link
Author

dsaveyn commented Apr 23, 2024

Does the extension management page reveal what the problem is?

No, nothing is displayed. It takes a while for the published extension to show up and when it does I can install it manually without a problem.

I'm currently updating a copy of our test environment (still on bc23) and it works perfectly fine there.

@freddydk
Copy link
Contributor

are you using s2s or impersonation for deployment?

@freddydk
Copy link
Contributor

Looks like impersonation (dev scope) - right?

@dsaveyn
Copy link
Author

dsaveyn commented Apr 23, 2024

Looks like impersonation (dev scope) - right?

Jep.

Here's the full script:

[CmdletBinding()]
param (
    [Parameter(Mandatory = $true)]
    [string]$AppFolder,    
    [Parameter(Mandatory = $true)]
    [string]$Environment,
    [Parameter(Mandatory = $true)]
    [string]$RefreshToken,
    [Parameter(Mandatory = $false)]
    [array]$PublishedApps,
    [Parameter(Mandatory = $false)]
    [Switch]$PublishTestApps = $false    
)

if (!(Get-Module -ListAvailable -Name 'BcContainerHelper')) { Install-Module BcContainerHelper -Force } 
Import-Module BCContainerHelper

Write-Host "Sorting Apps"
$AppsToInstall = Sort-AppFilesByDependencies -appFiles ((Get-ChildItem -Path $AppFolder -Filter '*.app' -Recurse).FullName)

Write-Host "Retrieving Authentication Context"
$AuthContext = New-BcAuthContext -refreshToken $RefreshToken

foreach ($App in $AppsToInstall) {
    $AppFileNameSplitted = [System.IO.Path]::GetFileName($App).Split("_")
    $Publisher = $AppFileNameSplitted[0]
    $Name = $AppFileNameSplitted[1]
    $Version = $AppFileNameSplitted[2]

    if ((-not $PublishTestApps) -and ($Name -like "*-test*")) { continue }

    $PublishedApp = $PublishedApps | Where-Object { ($_.publisher -eq $Publisher) -and ($_.displayName -eq $Name) }
    if ($null -ne $PublishedApp) {
        $PublishedAppVersion = "$($PublishedApp.versionMajor).$($PublishedApp.versionMinor).$($PublishedApp.versionBuild).$($PublishedApp.versionRevision)"
        if ($Version -eq $PublishedAppVersion) { 
            Write-Host "App $Name with version $Version for publisher $Publisher already installed" -ForegroundColor Yellow
            Remove-Item -Path $App
        }
    }
}

$bcContainerHelperConfig.NoOfSecondsToSleepAfterPublishBcContainerApp = 5

# Create temporary directory
$TempDirectoryName = [System.IO.Path]::Combine($env:TEMP, [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $TempDirectoryName -Force | Out-Null

Write-Host "The following Apps will be published:"
(Get-ChildItem -Path $AppFolder -Filter '*.app' -Recurse) | % {
    Write-Host "$($_.Name) (found in directory '$($_.Directory)')"     
    Copy-Item -Path $_.FullName -Destination $TempDirectoryName
}
   
Write-Host "Installing Apps"
Publish-BcContainerApp `
    -bcAuthContext $AuthContext `
    -environment $Environment `
    -appFile $TempDirectoryName `
    -dependencyPublishingOption default `
    -syncMode ForceSync 

# Remove temporary directory
Remove-Item $TempDirectoryName -Recurse

@freddydk
Copy link
Contributor

Could you try this:

Replace-DependenciesInAppFile -Path $appFile -replacePackageId

before publishing the app?

@dsaveyn
Copy link
Author

dsaveyn commented Apr 23, 2024

Could you try this:

Replace-DependenciesInAppFile -Path $appFile -replacePackageId

before publishing the app?

I'll get back to you about that in a bit. We are currently copying the bc24 environment to an environment with a new name and restoring our bc23 test environment.

@dsaveyn
Copy link
Author

dsaveyn commented Apr 23, 2024

Replace-DependenciesInAppFile -Path $appFile -replacePackageId

I'm afraid this doesn't help.

WARNING: The names of some imported commands from the module 'BCContainerHelper' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
Attempting authentication to https://api.businesscentral.dynamics.com/user_impersonation offline_access using refresh token...
Authenticated using refresh token as user ...
Authenticated to common, using tenant id ...
Replacing Package ID with new GUID
Replacing Package ID with new GUID
Replacing Package ID with new GUID
Publishing Dynavision_Dynavision Advanced Finance_23.0.8.18655_sandbox_23.1_w1.app to https://api.businesscentral.dynamics.com/v2.0/DynavisionDEV/dev/apps?SchemaUpdateMode=forcesync&DependencyPublishingOption=default
Status Code 422 : Unprocessable Entity
Er is geen gepubliceerde extensie die overeenkomt met de opgegeven parameterwaarden.

Publish-BcContainerApp Telemetry Correlation Id: 7dec0997-a498-41f2-9a98-065e920e5ed7
Status Code 422 : Unprocessable Entity
Er is geen gepubliceerde extensie die overeenkomt met de opgegeven parameterwaarden.
At C:\Program Files\WindowsPowerShell\Modules\BCContainerHelper\6.0.15\AppHandling\Publish-NavContainerApp.ps1:295 char:25
+                         throw $message
+                         ~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Status Code 422...meterwaarden.
:String) [], RuntimeException
    + FullyQualifiedErrorId : Status Code 422 : Unprocessable Entity
Er is geen gepubliceerde extensie die overeenkomt met de opgegeven parameterwaarden.

After the error above was thrown I checked the environment and the app was published but not installed:

image

It took over a minute for the app to show op in extension management. So it really looks like for some reason the publish has not completed yet when an attempt is made to install the app.

@freddydk
Copy link
Contributor

I have a repro of this - will investigate why this happens.

@dsaveyn
Copy link
Author

dsaveyn commented Apr 23, 2024

I have a repro of this - will investigate why this happens.

Thx! In the meantime we've restored our environment to BC23. We still have a copy of the BC24 environment for investigating the issue.

@freddydk
Copy link
Contributor

It looks like this problem is in the service and also happens from VS Code - we have people investigating

@freddydk
Copy link
Contributor

microsoft/AL#7721

@freddydk
Copy link
Contributor

This should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants