8

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?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
KenWin0x539
  • 329
  • 3
  • 8
  • Your title says `Test-ServiceFabricClusterConnection`, but your error message says `Get-ServiceFabricApplication`, so which is it? How is `$ApplicationName` populated? How is `@ClusterConnectionParameters` populated? Where do you call `Connect-ServerFabricCluster`? – Ansgar Wiechers Sep 21 '16 at 22:00
  • what happens if you call 'Connect-ServiceFabricCluster @ClusterConnectionParameters' with the same parameter settings from your dev machine? – LoekD Sep 22 '16 at 08:14
  • @AnsgarWiechers I revised my question – KenWin0x539 Sep 22 '16 at 14:34
  • @LoekD If I first connect to the server manually using Connect-ServiceFabricCluster and then run the script it works. All with the same parameters (ServerCertThumbprint, X509Credential, etc.). If I don't manually connect then I get the same instance is null issue – KenWin0x539 Sep 22 '16 at 15:02
  • 1
    Update! Solved it with dot sourcing http://stackoverflow.com/questions/35711540/how-do-i-deploy-service-fabric-application-from-vsts-release-pipeline – KenWin0x539 Sep 22 '16 at 19:44
  • What exactly did you change in your command when you used dot sourcing? – Tola Odejayi May 18 '17 at 17:49
  • I don't have it in front of me @TolaOdejayi but something like this on the build server powershell.exe . Deploy.ps1 ---ApplicationPackagePath .\Release ... – KenWin0x539 May 26 '17 at 21:03
  • 2
    @KenWin0x539 couldnt you answer your own question with a proper answer rather than comments? :-) I'm also having a similar problem and running Connect-ServerFabricCluster seems to fix it (I'm deploying to a local SF cluster) – bytedev Jan 11 '18 at 16:32

3 Answers3

3

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.

sysofwan
  • 191
  • 1
  • 9
0

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"

Umair Akbar
  • 578
  • 5
  • 11
0

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

to

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

AlignedDev
  • 8,102
  • 9
  • 56
  • 91