KenWin0x539
KenWin0x539

Reputation: 339

Publish to Service Fabric Cluster fails because of Test-ServiceFabricClusterConnection

I am using the Deploy-FabricApplication.ps1 script that is generated when you create a Service Fabric project to deploy my application.

When deploying to a Service Fabric cluster I can deploy locally if I first connect to a local cluster using Connect-ServiceFabricCluster. However, my build server does not run a local cluster instance so I am unable to first connect to a local instance. When I connect with Connect-ServiceFabricCluster @ClusterConnectionParameters I get data back on the connection that it was successful. When it gets to the publish and runs the Test-ServiceFabricClusterConnection command I get the following error.

WARNING: Unable to Verify connection to Service Fabric cluster.
Test-ServiceFabricClusterConnection : Cluster connection instance is null
At C:\ProgramFiles\MicrosoftSDKs\ServiceFabric\Tools\PSModule\ServiceFabricSDK\Publish-NewServiceFabricApplication.ps1:129 char:16
+         [void](Test-ServiceFabricClusterConnection)
+                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Test-ServiceFabricClusterConnection], NullReferenceException
    + FullyQualifiedErrorId : GetClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.TestClusterConnection

I have tried removing Test-ServiceFabricClusterConnection from the Publish-NewServiceFabricApplication.ps1 module and I get a different set of errors. No matter what I have tried to this point, if I first connect to a cluster it works but not if I connect via the powershell script.

Update! Solved Solved this using dot sourcing: How do I deploy service fabric application from VSTS release pipeline?

Upvotes: 8

Views: 3314

Answers (3)

sysofwan
sysofwan

Reputation: 191

Set $global:clusterConnection = $clusterConnection after calling Connect-ServiceFabricCluster or call Deploy-FabricApplication.ps1 using the dot source notation.

The call to Connect-ServiceFabricCluster sets a $clusterConnection variable on the local Powershell scope, which gets lost when calling other scopes. See this post for more information.

Upvotes: 3

AlignedDev
AlignedDev

Reputation: 8232

For me, it was changing from $clusterConnection = Connect-ServiceFabricCluster -ConnectionEndpoint $ClusterConnectionParameters.ConnectionEndpoint -ErrorAction Stop

to

Connect-ServiceFabricCluster -ConnectionEndpoint $ClusterConnectionParameters.ConnectionEndpoint -ErrorAction Stop

Upvotes: 0

Umair Akbar
Umair Akbar

Reputation: 588

Please check the certificate is installed correctly on your machine. I faced similar issue and installed the certificate and it worked. Also verify the store location is correctly set to

StoreLocation="LocalMachine"

if you installed certificate on local machine else set it to StoreLocation="CurrentUser"

Upvotes: 0

Related Questions