从PowerShell部署Service Fabric.错误 - > Get-ServiceFabricClusterManifest:群集连接实例为空

Tom*_*iak 11 powershell azure azure-service-fabric

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

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

启动我的脚本后,我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

在连接脚本和Deploy-FabricApplication.ps1中,我调用"Test-ServiceFabricClusterConnection",在两个脚本中它也在两个脚本中返回True我称之为"Get-ServiceFabricClusterManifest",在这两种情况下它都返回给我清单但是当我添加时"Test-ServiceFabricClusterConnection"到"Publish-UpgradedServiceFabricApplication.ps1"然后它返回了与前面提到的相同的错误,但是对于"Test-ServiceFabricClusterConnection"调用.

连接脚本的代码:

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
Run Code Online (Sandbox Code Playgroud)

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

感谢帮助

cha*_*isk 20

当设置调用Connect-ServiceFabricCluster局部$clusterConnection变量时.然后,某些SDK脚本会期望设置该变量,但由于您在不同的范围内执行脚本,因此该局部变量不可用.

您可以点源调用Deploy-FabricApplication.ps1

. .\Deploy-FabricApplication.ps1 -PublishProfileFile $PublishProfileFile -ApplicationPackagePath $ApplicationPackagePath -OverrideUpgradeBehavior $OverrideUpgradeBehavior -OverwriteBehavior $OverwriteBehavior -DeployOnly:$DeployOnly -UnregisterUnusedApplicationVersionsAfterUpgrade:$UnregisterUnusedApplicationVersionsAfterUpgrade -UseExistingClusterConnection:$true -SkipPackageValidation:$SkipPackageValidation
Run Code Online (Sandbox Code Playgroud)

或者创建一个$ global:clusterConnection变量,该变量包含本地$ clusterConnection变量

$global:clusterConnection = $clusterConnection
Run Code Online (Sandbox Code Playgroud)