简体   繁体   English

Azure云服务-监视部署

[英]Azure Cloud Service - Monitoring a deployment

Is there an event raised the moment a website is published and updated? 网站发布和更新后是否引发了事件?

I've tried Application_End in global.asax but that event does not seem to be raised. 我已经在global.asax中尝试过Application_End,但是似乎未引发该事件。

I suggest to use both Kudu and Microsoft ASP.NET WebHooks preview. 我建议同时使用Kudu和Microsoft ASP.NET WebHooks预览。

Kudu is the engine behind git deployments, WebJobs, and various other features in Azure Web Sites (Kudu source is on GitHub) Kudu是git部署,WebJobs和Azure网站中各种其他功能的引擎(Kudu来源在GitHub上)

With Kudu, Azure Web Sites have a support for web hooks. 使用Kudu,Azure网站支持Web挂钩。 There is an event "PostDeployment" that will be invoked whenever a deployment is complete with the result of that deployment. 每当部署完成并产生部署结果时,都会调用事件“ PostDeployment”。

Microsoft ASP.NET WebHooks preview provides a common model for receiving and processing WebHooks from any number of WebHook providers includign support for Kudu (Azure Web App Deployment). Microsoft ASP.NET WebHooks预览提供了一种通用模型,用于从任何数量的WebHook提供程序接收和处理WebHooks,包括对Kudu(Azure Web App部署)的支持。

So you may use Kudu WebHooks to get notified when an update has been deployed. 因此,您可以使用Kudu WebHooks在部署更新时得到通知。 (But that will require using Git Deploy instead of other ways to publish your web site). (但这将需要使用Git Deploy而不是其他方式来发布您的网站)。

Here is the way to do it : First Install the Microsoft.AspNet.WebHooks.Receivers.Azure Nuget package. 这是这样做的方法:首先安装Microsoft.AspNet.WebHooks.Receivers.Azure Nuget程序包。 The, Add these two lines to the WebApiConfig.Register method: 将这两行添加到WebApiConfig.Register方法中:

    config.InitializeReceiveKuduWebHooks();
    config.InitializeReceiveAzureAlertWebHooks();

Then Add a handler : 然后添加一个处理程序:

public class KuduWebHookHandler : WebHookHandler
{
public KuduWebHookHandler()
{
    Receiver = "kudu";
}

public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
{
    // Convert to POCO type
    KuduNotification notification = context.GetDataOrDefault<KuduNotification>();

    // Get the notification message
    string message = notification.Message;

    // Get the notification author
    string author = notification.Author;

    return Task.FromResult(true);
}
}

Then configure a secret that can validates that the WebHook requests indeed come from Kudu. 然后配置一个秘密,该秘密可以验证WebHook请求确实来自Kudu。 Use high-entropy values such as a SHA256 hash or similar, which you can get from http://www.freeformatter.com/hmac-generator.html . 使用高熵值,例如SHA256哈希或类似值,您可以从http://www.freeformatter.com/hmac-generator.html获得。 Also, set them through the Azure Portal instead of hard-coding them in the Web.config file Also, set them through the Azure Portal instead of hard-coding them in the Web.config file. 另外,通过Azure门户设置它们,而不是在Web.config文件中对其进行硬编码。另外,通过Azure门户设置它们,而不是在Web.config文件中对其进行硬编码。

There is a more complete Post on the subject here ( http://blogs.msdn.com/b/webdev/archive/2015/10/04/receive-webhooks-from-azure-alerts-and-kudu-azure-web-app-deployment.aspx ) 有关此主题的文章,更完整( http://blogs.msdn.com/b/webdev/archive/2015/10/04/receive-webhooks-from-azure-alerts-and-kudu-azure-web -app-deployment.aspx

Hope this helps Best regards Stéphane 希望这对您有所帮助Stéphane

I figured it out. 我想到了。 In the Application_Start event I bind 在Application_Start事件中,我绑定

RoleEnvironment.Stopping += RoleEnvironmentStopping;

private void RoleEnvironmentStopping(object sender, RoleEnvironmentStoppingEventArgs e)
{
       // do something ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM