microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
371 stars 238 forks source link

"duplicate package ID is detected" errors #3203

Open buzzwick opened 9 months ago

buzzwick commented 9 months ago

We are running into an obstacle that is preventing us from publishing to a couple of environments:

Deploying to xxx failed. Status Code 422 : Unprocessable Entity A duplicate package ID is detected. Cannot publish an extension with packageId: 'xxx', appId: 'xxx', name: 'xxx', publisher: 'xxx version: '22.2.43.0', because the same package ID already exists in a published extension with packageId: 'xxx', appId: 'xxx, name: 'xxx', publisher: 'xxx version: '22.2.43.0'

I get this error when publishing to a newly-created Sandbox environment, in a tenant with a Production environment with an earlier version published. I also get this error when a Publish has failed, and Publish to Environment is run a second time. It is as if the tenant has memory of app versions that are neither published nor installed, as far as a user can see.

In our other tenants, successive CI/CD runs can publish the same version to the Sandbox environments, over and over, regardless. Even in the same CI/CD run.

In #2326, this may have been referred to as "a limitation defined by Business Central." If so, where can we turn for guidance as to how to get around this limitation?

freddydk commented 9 months ago

I thought this problem had been fixed in the server - I will discuss this with the ModernDev / Server Team and get back.

freddydk commented 9 months ago

Are you using S2S when deploying the app to the sandbox environment or impersonation? (do you have a clientID/clientSecret registered in the sandbox or did you use New-BcAuthContext -includedevicelogin)

buzzwick commented 9 months ago

We are using the New_BcAuthContext -includedevicelogin

gntpet commented 7 months ago

We had the same issue with our pipelines. It was especially annoying when you could not trigger retry just for the failed jobs. What we did, we switched from New_BcAuthContext -includedevicelogin to S2S authentification.

Then, publishing is done using automation API, instead of development endpoint. When using automation API, it can see that the same app version is already installed, and just skips.

For some reason development endpoint (to be precise Publish-BcContainerApp) does not check if version is already installed or not, and tries to publish anyhow and fails. That would be great improvement.

The downside of using automation API is that it does not unpublish old versions, so your extension list gets polluted with old versions very quickly.

To create authcontext for S2S you should create app registration in AzurePortal and then use Freddy's commands to get authcontext. Plus you need register new "Microsoft Entra Application" in BC and give permissions for it EXTEN. MGT. - ADMIN|D365 AUTOMATION (not sure which ones)

$authcontext = New-BcAuthContext -clientID '' -clientSecret '' -tenantID ''
Get-ALGoAuthContext -bcAuthContext $authContext | Set-Clipboard