You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure中通过VSTS发布完成ARM模板部署后发送邮件及输出传递问题

Injecting ARM Template Outputs into SendGrid Email Notifications (Azure DevOps)

Great question! Let’s break this down step by step to get your Web App and SQL Server deployment details into that notification email, plus cover whether SendGrid is the right tool for the job.

1. First: Define Outputs in Your ARM Templates

You need to explicitly specify the values you want to share in your email directly in your ARM templates. This tells Azure to surface those values after deployment so Azure DevOps can pick them up.

For your Web App template, add an outputs section like this:

"outputs": {
  "webAppName": {
    "type": "string",
    "value": "[parameters('webAppName')]"
  },
  "webAppUrl": {
    "type": "string",
    "value": "[concat('https://', reference(resourceId('Microsoft.Web/sites', parameters('webAppName'))).defaultHostName)]"
  }
}

For your Azure SQL Server template, add similar outputs:

"outputs": {
  "sqlServerName": {
    "type": "string",
    "value": "[parameters('sqlServerName')]"
  },
  "sqlServerFqdn": {
    "type": "string",
    "value": "[reference(resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))).fullyQualifiedDomainName]"
  }
}

2. Capture Outputs as Azure DevOps Pipeline Variables

In your Azure DevOps Release Pipeline, find the Azure Resource Group Deployment task that runs your ARM templates. Scroll down to the Outputs section and check the box labeled Publish outputs as pipeline variables.

Once you do this, your ARM outputs will be available as pipeline variables using the syntax $(armOutputs.<OutputName>). For example:

  • $(armOutputs.webAppName)
  • $(armOutputs.sqlServerFqdn)

3. Plug Variables into the SendGrid Email Task

Now head to your SendGrid Email task. For the email body, you can use plain text or HTML (HTML works better for readability). Here’s an example HTML body that uses your pipeline variables:

<p>Hi [Project Manager Name],</p>
<p>Our infrastructure deployment to Azure has completed successfully! Here are the key details:</p>
<ul>
  <li><strong>Web App:</strong> $(armOutputs.webAppName) - <a href="$(armOutputs.webAppUrl)">$(armOutputs.webAppUrl)</a></li>
  <li><strong>SQL Server:</strong> $(armOutputs.sqlServerName) - FQDN: $(armOutputs.sqlServerFqdn)</li>
</ul>
<p>Let me know if you need any additional information!</p>

Don’t forget to set the Body type to "HTML" in the SendGrid task if you use this format.

Absolutely! SendGrid is a fantastic choice here. It’s a fully managed, reliable email service that integrates natively with Azure DevOps, so you don’t have to build any custom email logic. It lets you customize the email content exactly how you want (including dynamic values like your ARM outputs), and scales easily if you need to send more notifications down the line.

If you’re curious about alternatives, Azure Monitor alerts can send emails when deployments complete, but they’re less flexible for customizing the email body and including specific deployment details like your Web App/SQL Server names. SendGrid is the better fit for your use case.

内容的提问来源于stack exchange,提问作者Pradeep

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:08:29