Expand the service fabric from PowerShell. Error & # 8594; Get-ServiceFabricClusterManifest: cluster connection instance is null

I am trying to publish a Service Fabric application for Azure using powershell. I want to connect to a cluster and then call the script "Deploy-FabricApplication.ps1" (the one that is created when creating a new project in visual studio).

To do this, I created a new script file that is responsible for connecting to the cluster, and then from the same script file that I call "Deploy-FabricApplication.ps1".

After running my script, I get the following error:

Get-ServiceFabricClusterManifest : Cluster connection instance is null At C:\Program Files\Microsoft SDKs\Service Fabric\Tools\PSModule\ServiceFabricSDK\Publish-UpgradedServiceFabricApplication.ps1:116 char:28 + $clusterManifestText = Get-ServiceFabricClusterManifest + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [Get-ServiceFabricClusterManifest], NullReferenceException + FullyQualifiedErrorId : GetClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.GetClusterManifest 

In the connection of the script and Deploy-FabricApplication.ps1, I call "Test-ServiceFabricClusterConnection" and in both scripts it returns True also in both scripts, I call "Get-ServiceFabricClusterManifest" and in both cases it returns the manifest to me, but when I added " Test-ServiceFabricClusterConnection "in" Publish-UpgradedServiceFabricApplication.ps1 ", then it returned the same error as mentioned above, but for calling" Test-ServiceFabricClusterConnection ".

Code for connecting the script:

 Param ( [String] $PublishProfileFile, [String] $ApplicationPackagePath, [Switch] $DeployOnly, [Boolean] $UnregisterUnusedApplicationVersionsAfterUpgrade, [String] [ValidateSet('None', 'ForceUpgrade', 'VetoUpgrade')] $OverrideUpgradeBehavior = 'None', [String] [ValidateSet('Never','Always','SameAppTypeAndVersion')] $OverwriteBehavior = 'Never', [Switch] $SkipPackageValidation, [String] $ConnectionEndpoint, [String] $ServerCertThumbprint, [String] $FindType, [String] $FindValue, [String] $StoreLocation, [String] $StoreName ) $connectArgs = @{ ConnectionEndpoint = $ConnectionEndpoint; X509Credential = $True; StoreLocation = $StoreLocation; StoreName = $StoreName; ServerCertThumbprint = $ServerCertThumbprint; FindType = $FindType; FindValue = $FindValue } try { Connect-ServiceFabricCluster @connectArgs; $connection = Get-ServiceFabricClusterConnection; Write-Host $connection; $m = Get-ServiceFabricClusterManifest Write-Host $m; } catch [System.Fabric.FabricObjectClosedException] { Write-Warning "Service Fabric cluster may not be connected." throw } .\Deploy-FabricApplication.ps1 -PublishProfileFile $PublishProfileFile -ApplicationPackagePath $ApplicationPackagePath -OverrideUpgradeBehavior $OverrideUpgradeBehavior -OverwriteBehavior $OverwriteBehavior -DeployOnly:$DeployOnly -UnregisterUnusedApplicationVersionsAfterUpgrade:$UnregisterUnusedApplicationVersionsAfterUpgrade -UseExistingClusterConnection:$true -SkipPackageValidation:$SkipPackageValidation 

To summarize, I have no idea how to connect to the cluster and then use it in Deploy-FabricApplication.ps1

thanks for the help

+6
source share
1 answer

Calling Connect-ServiceFabricCluster sets the local $clusterConnection variable. Some SDK scripts expect the variable to be set, but since you are running your script in different areas, this local variable is not available to them.

You can either calculate the source of the call for Deploy-FabricApplication.ps1

 . .\Deploy-FabricApplication.ps1 -PublishProfileFile $PublishProfileFile -ApplicationPackagePath $ApplicationPackagePath -OverrideUpgradeBehavior $OverrideUpgradeBehavior -OverwriteBehavior $OverwriteBehavior -DeployOnly:$DeployOnly -UnregisterUnusedApplicationVersionsAfterUpgrade:$UnregisterUnusedApplicationVersionsAfterUpgrade -UseExistingClusterConnection:$true -SkipPackageValidation:$SkipPackageValidation 

or create a $ global: clusterConnection variable that contains the local $ clusterConnection variable

 $global:clusterConnection = $clusterConnection 
+11
source

All Articles