本文介绍了从Powershell部署Service Fabric.错误-> Get-ServiceFabricClusterManifest:群集连接实例为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Powershell将Service Fabric应用程序发布到Azure.我想连接到群集,然后调用脚本"Deploy-FabricApplication.ps1"(在Visual Studio中创建新项目时生成的脚本)

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

为此,我创建了一个新的脚本文件,该文件负责与群集连接,然后从同一脚本文件中调用"Deploy-FabricApplication.ps1".

To do that I have created new script file which is responsible for connecting with cluster and then from that same script file I am calling "Deploy-FabricApplication.ps1".

启动脚本后,出现以下错误:

After launching my script I am getting 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

在连接脚本和Deploy-FabricApplication.ps1中,我正在调用"Test-ServiceFabricClusterConnection",并且在两个脚本中它都返回True,在两个脚本中我都在调用"Get-ServiceFabricClusterManifest",并且在两种情况下,它都会返回给我清单,但是当我已经在"Publish-UpgradedServiceFabricApplication.ps1"中添加了"Test-ServiceFabricClusterConnection",然后它返回了与前面提到的相同的错误,但调用了"Test-ServiceFabricClusterConnection".

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

用于连接脚本的代码:

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

总而言之,我不知道如何建立与群集的连接,然后在Deploy-FabricApplication.ps1中使用它

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

感谢帮助

推荐答案

调用Connect-ServiceFabricCluster时,设置了本地$clusterConnection变量.然后,某些SDK脚本会期望设置该变量,但是由于您要在不同的范围内执行脚本,因此它们无法使用该本地变量.

When calling Connect-ServiceFabricCluster a local $clusterConnection variable is set. Some of the SDK scripts then expect that variable to be set, but because you're executing your script in different scope, that local variable isn't available to them.

您可以将对Deploy-FabricApplication.ps1的调用标记为点源.

You can either dot source the call to Deploy-FabricApplication.ps1

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

或创建一个包含全局$ clusterConnection变量的$ global:clusterConnection变量

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

$global:clusterConnection = $clusterConnection

这篇关于从Powershell部署Service Fabric.错误-> Get-ServiceFabricClusterManifest:群集连接实例为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 11:06