我正在尝试使用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”,并且都返回给我清单。但是,当我将“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
会得到以下结果:Connect-ServiceFabricCluster : The object is closed. At line:1 char:1 + Connect-ServiceFabricCluster + CategoryInfo : InvalidOperation: (:) [Connect-ServiceFabricCluster], FabricObjectClosedException + FullyQualifiedErrorId : TestClusterConnectionErrorId,Microsoft.ServiceFabric.Powershell.ConnectCluster
- Tim Abell