powershell - 从 powershell 部署 Service Fabric。错误 -> 获取 ServiceFabricClusterManifest : Cluster connection instance is null

标签 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

在连接脚本和 Deploy-FabricApplication.ps1 中,我调用“Test-ServiceFabricClusterConnection”,并且在这两个脚本中,它都返回 True;在这两个脚本中,我调用“Get-ServiceFabricClusterManifest”,并且在这两种情况下,它都会返回给我 list ,但是当我已将“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

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

感谢帮助

最佳答案

调用 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

或创建一个包含本地 $clusterConnection 变量的 $global:clusterConnection 变量

$global:clusterConnection = $clusterConnection

关于powershell - 从 powershell 部署 Service Fabric。错误 -> 获取 ServiceFabricClusterManifest : Cluster connection instance is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38103343/

相关文章:

azure - 在哪里设置和访问服务结构每个环境的运行时配置参数?

sql-server - 如何使用输出和退出代码运行 SQL Server 代理 Powershell 脚本

powershell - Get-Content 无法读取通过 WMI 检索的路径

c# - 值类型的依赖注入(inject)

Windows Server 2019 上的 Azure 管道 powershell 和 git 在输出中出现错误

Azure Function 的 IP 地址超出了 VNet 的范围

kubernetes - Kubernetes 和 Service Fabric 之间的区别

powershell - 电子邮件正文每个字符串换行

powershell - Copy-Item 是否更改 PowerShell 中目标参数的类型

在 Windows Azure 上托管时 Wcf 绑定(bind)的差异