如何通过 VSTS 将 Azure WebJob 和 App 部署到同一个 App Service? [英] How do you deploy an Azure WebJob and App to the same App Service via VSTS?

本文介绍了如何通过 VSTS 将 Azure WebJob 和 App 部署到同一个 App Service?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Visual Studio 2017 解决方案,其中包含一个 ASP.NET Web 应用程序项目(称为 UI)和一个 Azure WebJob 项目(称为 WebJobs).我已将两者配置为从 Visual Studio 中部署到 Azure(右键单击、发布)到同一个应用服务.该解决方案还配置为在我推送到 VSTS 时构建.

I have a Visual Studio 2017 solution with both an ASP.NET Web Application project (called UI) and an Azure WebJob project (called WebJobs). I have configured both to deploy to Azure from within Visual Studio (right click, publish) to the same App Service. The solution is also configured to build whenever I push to VSTS.

我想设置 VSTS,以便在成功构建后也部署这两个项目,但我遇到了问题.

I would like to set up VSTS to also deploy both projects upon successful builds but I cam having problems.

我的理解是,要实现这一点,我需要创建一个发布定义,该定义与我的构建定义相关联,并将部署 Azure 应用服务"任务添加到管道中.我试过这个并得到一个错误,因为在工件文件夹中发现了多个 .zip 文件,它建议我使过滤器更具体,所以我从 $(System.DefaultWorkingDirectory) 更改了包或文件夹"选项/**/*.zip$(System.DefaultWorkingDirectory)/**/UI.zip.这解决了错误,但现在显然它只是部署我的应用程序(UI).

My understanding is that to achieve this I need to create a release definition that is linked to my build definition with a "Deploy Azure App Service" task added to the pipeline. I tried this and got an error because more than one .zip file was found in the artifacts folder which advised me to make the filter more specific, so I changed the "Package or folder" option from $(System.DefaultWorkingDirectory)/**/*.zip to $(System.DefaultWorkingDirectory)/**/UI.zip. This got around the error but now obviously it's only deploying my App (UI).

我的下一步是尝试为 WebJob 项目创建一个单独的环境,并将 $(System.DefaultWorkingDirectory)/**/WebJobs.zip 指定为包.现在两个环境都成功"部署了,但它破坏了我的应用程序,我很确定它已经将 WebJob 部署在应用程序的顶部(我不知道如何确认这个信念......).

My next step was to try creating a separate Environment for the WebJob project and specify $(System.DefaultWorkingDirectory)/**/WebJobs.zip as the Package. Now both environments "successfully" deploys but it breaks my App and I am pretty sure it has deployed the WebJob over the top of the App (I don't know how to confirm this belief...).

我注意到,当您将环境添加到发布定义并选择模板时,在Azure 应用服务部署"下会显示:将您的应用程序部署到 Azure 应用服务.从 Windows、Linux、容器上的 Web 应用中选择,Function Apps or Web Jobs" but when choose this template WebJob isn't listed in the "App Type" drop down!

I notice that when you add an Environment to the release definition and choose a template, under "Azure App Service Deployment" it says: "Deploy your application to Azure App Services. Choose from Web App On Windows, Linux, Containers, Function Apps or Web Jobs" but when choose this template WebJob isn't listed in the "App Type" drop down!

我在网上找到了一些关于从 VSTS 部署 WebJobs 的资源,但它们都已过时,并且所描述的选项不再与 VSTS 中当前的选项匹配.

I have found a few resources online regarding the deployment of of WebJobs from VSTS but they are all outdated and the options described no longer match those currently in VSTS.

David Ebbostarian chen 的回答如下.

首先,您必须在 Visual Studio 中右键单击您的 Web App 项目,然后选择 Add > Existing Project as Azure WebJob 并按照向导进行操作.接下来,您必须确保 VSTS 部署任务通过更新 Package or folder 路径过滤器只找到一个要部署的 .zip 包,以便它只找到 Web App 的那个;在我的例子中是 $(System.DefaultWorkingDirectory)/**/UI.zip.

Firstly you must right click your Web App project in Visual Studio and select Add > Existing Project as Azure WebJob and follow the wizard. Next you must ensure that the VSTS deploy task only finds one .zip package to deploy by updating the Package or folder path filter so it only finds the Web App's one; in my case it was $(System.DefaultWorkingDirectory)/**/UI.zip.

非常感谢 @DavidEbbo 和 @starianchen 的帮助!

Big thanks to @DavidEbbo and @starianchen for their help!

推荐答案

您所要做的就是通过右键单击您的 Web 应用并选择以下选项来创建 WebJob 项目:

All you have to do is create the WebJob project by right clicking on your Web App and choosing:

Add / New Azure WebJob project

或者如果您的解决方案中已经有一个 WebJobs 项目:

Or if you already have a WebJobs project in the solution:

Add / Existing WebJob project

完成此操作后,发布 Web 应用程序会自动将 WebJob 发布到它所属的位置.这一切都发生在一个 zip 文件中,在 VSTS 中没有什么特别的.请勿尝试单独发布 WebJob 项目.

Once you do that, publishing the Web App automatically publishes the WebJob where it belongs. It all happens in a single zip file, and there is nothing special to do in VSTS. Do not try to publish the WebJob project individually once you do that.

这篇关于如何通过 VSTS 将 Azure WebJob 和 App 部署到同一个 App Service?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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