Service fabric deployment tries to create new application instead of upgrading

We’re facing an issue with CI for an Azure Service Fabric application where the deployment to the service fabric cluster fails because it appears to be trying to create a new application rather than upgrading the currently installed version. The deployments fails as it cannot create an application on the cluster with the same name. Here is the log:

16:57:16 Error | An application with name ‘fabric:/Develop-TestMicroService’ already

16:57:16 Error | exists, its Type is ‘TestMicroServiceType’ and Version is
16:57:16 Error | ‘0.1.18140-Sha-69fc8b0’.
16:57:16 Error | You must first remove the existing application before a new
16:57:16 Error | application can be deployed or provide a new name for the application.
16:57:16 Error | At C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricS
16:57:16 Error | DK\Publish-NewServiceFabricApplication.ps1:175 char:17
16:57:16 Error | + throw $errMsg
16:57:16 Error | + ~~~~~~~~~~~~~
16:57:16 Error | + CategoryInfo : OperationStopped: (An application …he applicat
16:57:16 Error | ion.:String) [], RuntimeException
16:57:16 Error | + FullyQualifiedErrorId : An application with name ‘fabric:/Develop-TestMi
16:57:16 Error | croService’ already exists, its Type is ‘TestMicroServiceType’ and Version
16:57:16 Error | is ‘0.1.18140-Sha-69fc8b0’.
16:57:16 Error | You must first remove the existing application before a ne
16:57:16 Error | w application can be deployed or provide a new name for the application.
16:57:16 Error | Script ‘C:\Octopus\Work\20170803155529-137220-6\staging\DeployToServiceFabric.ps1’ returned non-zero exit code: 1
16:57:16 Error | Running rollback conventions…
16:57:16 Error | Script ‘C:\Octopus\Work\20170803155529-137220-6\staging\DeployToServiceFabric.ps1’ returned non-zero exit code: 1
16:57:17 Verbose | Updating manifest with output variables
16:57:17 Verbose | Updating manifest with action evaluated variables
16:57:17 Fatal | The remote script failed with exit code 1

Note that octopus is running Publish-NewServiceFabricApplication.ps1, I presume it should be running an “Upgrade” version of this script?

Does anyone know what we’re doing wrong?

House Keeping:

  • Sanitised deployment log attached
  • Version: 3.16.0
  • Diagnostics: We couldn’t find anything interesting here

ServerTasks-137220.log.txt (10 KB)

Hi,

Thanks for getting in touch.

In your Octopus deployment step, you’ll need to override the upgrade behaviour to Force Upgrade, create a new release to deploy and it should then go down the upgrade path of the Service Fabric script.

If you want to trace through exactly what’s happening, you can view the script that gets used by Calamari here (Note the if ($IsUpgrade -and $AppExists) line of the PowerShell that will take you down to the Publish-UpgradedServiceFabricApplication command.

You can also customise/override this PowerShell script if you wish. See the “Customizing the deployment process” section of the Service Fabric documentation.

Hope this helps.

Cheers
Mark

Hi Mark,

Thanks for your response.

That appears to have worked! I’m sure we’d tried to force the upgrade in
the past, however thinking back I’m not sure we created a new release which
must have been the key.

Thanks for also including the information about the the Calamari script, I
knew we must have been doing something wrong in the publish profile. For
the benefit of other readers:

$IsUpgrade = ($publishProfile.UpgradeDeployment -and $publishProfile
.UpgradeDeployment.Enabled -and $OverrideUpgradeBehavior -ne ‘VetoUpgrade’
) -or $OverrideUpgradeBehavior -eq ‘ForceUpgrade’

Kind Regards,