如何将Azure WebJob部署为自动VSTS部署的一部分

Jaj*_*415 10 azure azure-webjobs webjob azure-devops

有没有办法让我的Azure WebJob自动部署而无需右键单击并选择"每次发布为Azure WebJob"?即当我签入我的解决方案时,它会自动部署到Azure Portal webjob部分

Pet*_*ter 5

While I tried to accomplish this, I found out that there is no tooling support for dotnet core projects as of now. The proposed webjobs.props/ msbuild solutions are all dotnet framework specific.

However I also found out that a webjob can be anything that's executable on the local machine (could be node.js or just a batch command).


The key is to understand how WebJobs are recognized by the host:

  • A WebJob on a Windows host is (by what I gathered from experimenting with it) just a run.cmd file that contains instructions on how to start the webJob. For dotnet core that would be dotnet MyDll.dll %* (%* to pass arguments for output redirection etc. down from the host).
  • Now depending on wether the job is continuous or triggered the run.cmd file needs to be located either at app_data/jobs/continuous/[NameOfJob] or app_data/jobs/triggered/[NameOfJob]. For the triggered job you could also add a schedule using a settings.job file like described here.
  • If there is a run.cmd at the proper location it will be recognized as a WebJob

Now to deploy a webjob using VSTS regardless of the runtime framework follow these steps:

  1. Build/Publish your WebJob if necessary to get the executables
  2. Add a run.cmd file next to your webjob executables that contains the proper startup instructions. You could also add settings.job here if needed.
  3. Create the folder hierarchy app_data/jobs/[triggered/continuous]/[nameOfJob] and copy your executables into the lowest folder. Make sure run.cmd is directly under the [nameOfJob]/ directory
  4. 压缩 app_data 文件夹,以便 zip-package 包含整个层次结构
  5. 使用普通的 Azure 应用服务部署任务发布 zip 文件(就像部署 Web 应用程序一样)

就是这样。


Jan*_*n_V 4

是的你可以。

\n\n

布雷迪·加斯特 (Brady Gaster) 在博客文章中写到了这一点(我自己还没有尝试过)。

\n\n

据我所知,TL;DR; 总结如下:

\n\n
\n

将名为 webjobs.props 的文件添加到您要发布的 Web 应用程序项目或控制台应用程序的属性文件夹\xe2\x80\x99

\n
\n\n

之后,编辑文件,使ManagementCertificateSubscriptionIdPublishSettingsPath填充正确的数据。

\n\n

现在您应该能够使用命令发布文件

\n\n
msbuild WebJobDemo.Web.csproj /p:DeployOnBuild=true /p:PublishProfile=WebJobDemo /p:VisualStudioVersion=12.0 /p:Password=asdfasdf\n
Run Code Online (Sandbox Code Playgroud)\n\n

(注意,帖子是针对VS2013写的)

\n\n

之后您应该会看到类似这样的内容。\n部署输出

\n\n

当然,只要将某些内容签入存储库,您就可以在 VSTS(或任何其他与此相关的构建/部署工具)中自动执行此操作。

\n\n

关于如何通过命令行在 VSTS 中执行此操作的(相当完整的)答案可以在此答案中找到:https ://stackoverflow.com/a/45703975/352640

\n