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

问题描述

我有一个 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 应用服务"任务添加到管道中.我尝试了这个并得到一个错误,因为在 artifacts 文件夹中发现了不止一个 .zip 文件,它建议我使过滤器更具体,所以我从 $(System.DefaultWorkingDirectory) 更改了Package or folder"选项/**/*.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 的回答如下.

My problem was solved as a result of both David Ebbo's and starian chen's answers below.

首先,您必须在 Visual Studio 中右键单击您的 Web App 项目,然后选择添加 > 现有项目作为 Azure WebJob 并按照向导进行操作.接下来,您必须通过更新包或文件夹路径过滤器来确保 VSTS 部署任务只找到一个要部署的 .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 应用程序并选择:

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 应用程序会自动将 Web 作业发布到它所属的位置.这一切都发生在一个 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 Web 作业和应用部署到同一个应用服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:30