如何从VSTS发布管道部署服务结构应用程序? [英] How do I deploy service fabric application from VSTS release pipeline?

查看:98
本文介绍了如何从VSTS发布管道部署服务结构应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此文档,我已经在Visual Studio Team Services中为Service Fabric应用程序配置了CI构建:

I have configured a CI build for a Service Fabric application, in Visual Studio Team Services, according to this documentation: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-set-up-continuous-integration

但是,我没有执行CI构建来发布,而是仅执行Build和Package任务,并在下拉菜单中包含所有与Service Fabric相关的输出,例如pkg文件夹,脚本,发布配置文件和应用程序参数.这样,我就可以将其传递到新的Release管道(基于代理的发行版)中,以进行服务结构应用程序的实际部署.

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.

推荐答案

(从Deploy-FabricApplication.ps1中)调用Connect-ServiceFabricCluster函数时,将在调用Connect-ServiceFabricCluster之后设置本地$clusterConnection变量.您可以使用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脚本,将$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.

我不确定通过发布管道运行脚本时是否有使用点源的方法,但是您可以通过Connect-ServiceFabricCluster$clusterConnection变量设置为全局变量,以作为解决方法称呼.编辑您的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  

顺便说一句,您可能要考虑设置自定义构建/发布任务,而不是使用各种Deploy-FabricApplication.ps1脚本来部署Service Fabric应用程序.

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发布管道部署服务结构应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆