问题描述
我已经根据以下文档在 Visual Studio Team Services 中为 Service Fabric 应用程序配置了 CI 构建:https://azure.microsoft/en-us/documentation/articles/service-fabric-set-up-continuous-integration
I have configured a CI build for a Service Fabric application, in Visual Studio Team Services, according to this documentation: https://azure.microsoft/en-us/documentation/articles/service-fabric-set-up-continuous-integration
但不是让我的 CI 构建执行发布,我只执行构建和打包任务,并在 drop 中包含所有与 Service Fabric 相关的输出,例如 pkg 文件夹、脚本、发布配置文件和应用程序参数.通过这种方式,我可以将其传递给新的发布管道(基于代理的发布),以执行我的服务结构应用程序的实际部署.
But instead of having my CI build do the publishing, I only perform the Build and Package tasks, and include all Service Fabric related output, such as pkg folder, scripts, publish profiles and application parameters, in the drop. This way I can pass it along to the new Release pipeline (agent-based releases) to do the actual deployment of my service fabric application.
在我的发布定义中,我有一个 Azure Powershell 任务,它使用 ARM 端点(配置了适当的服务主体).
In my release definition I have a single Azure Powershell task, that uses an ARM endpoint (with proper service principals configured).
当我将我的应用程序部署到现有服务结构集群时,我使用默认的 Deploy-FabricApplication cmdlet 传递 pkg 文件夹和配置为连接到现有集群的发布配置文件.
When I deploy my app to an existing service fabric cluster, I use the default Deploy-FabricApplication cmdlet passing along the pkg folder and a publish profile that is configured with a connection to the existing cluster.
发布失败并显示错误消息集群连接实例为空".我不明白为什么?
The release fails with an error message "Cluster connection instance is null". And I cannot understand why?
做一些调试我发现:Deploy-FabricApplication cmdlet 可以很好地执行 Connect-ServiceFabricCluster cmdlet,但是一旦 Publish-NewServiceFabricApplication cmdlet 接管执行,集群连接就会丢失.
Doing some debugging I have found that: The Deploy-FabricApplication cmdlet executes the Connect-ServiceFabricCluster cmdlet just fine, but as soon as the Publish-NewServiceFabricApplication cmdlet takes over execution, then the cluster connection is lost.
我希望使用服务结构 cmdlet 可以实现这种情况,但我不知道如何在部署期间保持集群连接打开.
I would expect that this scenario is possible using the service fabric cmdlets, but I cannot figure out how to keep the cluster connection open during depoyment.
更新:文档链接不再引用 Service Fabric powershell 脚本,因此不再记录此问题的前提条件.这篇文章现在提到了 VSTS 构建和发布任务,它比我尝试使用的 powershell cmdlet 更受欢迎.
UPDATE: The link to the documentation no longer refers to the Service Fabric powershell scripts, so the pre-condition for this question is no longer documented. The article now refers to the VSTS build and release tasks, which can be prefered over the powershell cmdlets I tried to use.
推荐答案
当 Connect-ServiceFabricCluster
函数被调用(来自 Deploy-FabricApplication.ps1)本地 $clusterConnection
函数> 变量在调用 Connect-ServiceFabricCluster
后设置.你可以看到使用 Get-Variable
.
When the Connect-ServiceFabricCluster
function is called (from Deploy-FabricApplication.ps1) a local $clusterConnection
variable is set after the call to Connect-ServiceFabricCluster
. You can see that using Get-Variable
.
不幸的是,某些 SDK 脚本中存在逻辑,期望该变量被设置,但由于它们在不同的范围内运行,所以该局部变量不可用.
Unfortunately there is logic in some of the SDK scripts that expect that variable to be set but because they run in a different scope, that local variable isn't available.
它在 Visual Studio 中有效,因为 Deploy-FabricApplication.ps1 脚本是使用 点源符号调用的a>,它将 $clusterConnection
变量放在当前范围内.
It works in Visual Studio because the Deploy-FabricApplication.ps1 script is called using dot source notation, which puts the $clusterConnection
variable in the current scope.
我不确定在通过发布管道运行脚本时是否有办法使用点源,但作为一种解决方法,您可以在 $clusterConnection
变量之后立即将其设为全局通过 Connect-ServiceFabricCluster
调用设置.编辑您的 Deploy-FabricApplication.ps1
脚本并在连接逻辑之后添加以下行(~第 169 行):
I'm not sure if there is a way to use dot sourcing when running a script though the release pipeline but you could, as a workaround, make the $clusterConnection
variable global right after it's been set via the Connect-ServiceFabricCluster
call. Edit your Deploy-FabricApplication.ps1
script and add the following line after the connection logic (~line 169):
$global:clusterConnection = $clusterConnection
顺便说一句,您可能需要考虑设置自定义构建/发布 部署 Service Fabric 应用程序的任务,而不是使用各种 Deploy-FabricApplication.ps1 脚本.
By the way, you might want to consider setting up custom build/release tasks that deploy a Service Fabric application, rather than using the various Deploy-FabricApplication.ps1 scripts.
这篇关于如何从 VSTS 发布管道部署 Service Fabric 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论