Register-ServiceFabricApplicationType not working

I have a Deploy to Service Fabric cluster step provided by Octopus Deploy and in the post deploy script I try to deploy the Patching Orchestrator App provided by Microsoft.

The step is already connected to the cluster in the post-deploy section
This is what I am trying to run:
Copy-ServiceFabricApplicationPackage -ApplicationPackagePath $ApplicationPackagePath -ImageStoreConnectionString $ImageStoreConnectionString -CompressPackage -ApplicationPackagePathInImageStore $ApplicationPackagePath

Register-ServiceFabricApplicationType PatchOrchestrationApplication

New-ServiceFabricApplication fabric:/PatchOrchestrationApplication PatchOrchestrationApplicationType $ApplicationVersion -ApplicationParameter $ApplicationParameters

Register-ServiceFabricApplicationType run from my PC goes fine, but when I run the exact same lines from the Octopus post-deploy script, I get this error.

"Register-ServiceFabricApplicationType : The BuildLayout of the application in D:\SvcFab\ImageBuilderProxy\AppType\67e94be3-a595-4fc3-ae02-4ae25363c653 is invalid. ServiceManifest.xml is missing for service CoordinatorServicePkg.
At D:\Octopus\Work\20191108162838-433566-138623\staging\Octopus.Action.CustomScripts.PostDeploy.ps1:23 char:1

  • Register-ServiceFabricApplicationType PatchOrchestrationApplication
    • CategoryInfo : InvalidOperation: (Microsoft.Servi…usterConnection:ClusterConnection) [Register-ServiceFabricApplicationType], FabricException
    • FullyQualifiedErrorId : RegisterApplicationTypeErrorId,Microsoft.ServiceFabric.Powershell.RegisterApplicationType "

I even tried running these commands from an RDP connection in the octopus server itself, and they ran fine.

Hi,

Thanks for getting in touch.

I don’t think we’ve seen this particular issue before. However, if it works when you try to deploy it from your PC, then it is likely that something has not been included correctly in the package that is prepared for Octopus.

I would recommend comparing the contents of your package to the files you have on your PC, and make sure that everything has been included. Have a careful read (or re-read) of https://octopus.com/docs/deployment-examples/azure-deployments/service-fabric/packaging to make sure you are preparing your package in the correct way for Service Fabric.

Finally, I have also found this blog post which might be revelant, and indicates that all of the Platform and Build Configuration settings should match: https://blog.abatishchev.ru/2018/03/05/the-buildlayout-of-the-application-is-invalid-code-is-missing-for-service/

Hope that helps,

Regards
Tom

I have checked everything you mentioned and it checks out.
When I try to replicated the behaviour I use the exact same package which I download from Octopus.

Anyway I made it work in the end by adding a new step (Powershell with service fabric context) and running the code from there. I cannot understand why the same code in the “Post-Deploy Script” section of a Service Fabric Deployment step would fail, but it works in the other step.

I think it is still worth investigating on your part, but for what we are concerned, you can close the case as I found the workaround.