简体   繁体   English

使用 Azure DevOps 部署时,在 web.config 中设置发布名称

[英]Set Release name in web.config when deploying with Azure DevOps

We're building and deploying our application to 30 separate web apps every night, and I would like to know which release every web app is currently on.我们每晚都在构建我们的应用程序并将其部署到 30 个单独的 web 应用程序,我想知道每个 web 应用程序当前在哪个版本上。 For instance "Release-12345".例如“Release-12345”。

The value exists in the release variable Release.ReleaseName from Release variables (MS doc) , but I have no idea on how to make my pipeline use that value.该值存在于发布变量 (MS doc)的发布变量Release.ReleaseName中,但我不知道如何让我的管道使用该值。 My approach for now is to write it to the web.config, and the let the application read that value on demand.我现在的方法是将它写入 web.config,然后让应用程序按需读取该值。 But if there's another, more efficient or "correct" way of doing it, I'm open for anything.但如果有另一种更有效或“正确”的方法,我愿意接受任何事情。

It's a classic usage of "replace tokens" tasks, there are many extensions in the marketplace , the most popular is Replace Tokens .这是“替换令牌”任务的经典用法, 市场上有很多扩展,最受欢迎的是替换令牌

You need to add a placeholder in the web.config , for example:您需要在web.config中添加一个占位符,例如:

<add key="Release_number" value="#{Release_number}#" />

In the release variables you need to add a variable Release_number with the value $(Release.ReleaseName) , and add the Replace Tokens task in your release pipeline with configuration of:在发布变量中,您需要添加一个值为$(Release.ReleaseName)的变量Release_number ,并在您的发布管道中添加 Replace Tokens 任务,配置如下:

  • Target Files: web.config目标文件: web.config
  • Token Prefix: #{令牌前缀: #{
  • Token Suffix: }#令牌后缀: }#

Now, the task will search inside the web.config file strings that match the pattern and will replace them with the value from the release variables.现在,该任务将在web.config文件中搜索与模式匹配的字符串,并将其替换为发布变量中的值。

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

相关问题 为什么Azure DevOps Release Transforming Web.config - Why is Azure DevOps Release Transforming Web.config Azure Function 从 Azure devops 管道部署时无法访问运行时 - Azure Function Runtime Unreachable when deploying from Azure devops pipeline 设置 Azure devops 使用 REST API 发布管道变量 - Set Azure devops Release pipeline variable using REST API Azure DevOps - React App - 在发布管道中设置环境变量 - Azure DevOps - React App - Set Environment Variables in Release Pipeline 在发布管道中执行阶段时触发不同的存储库 - Azure DevOps - Trigger different repository when execute stage in a release pipeline - Azure DevOps Azure DevOps 发布 - 当发布开始时避免阶段批准 - Azure DevOps Releases - Avoid the stage approval when the release starts on scheduling Azure DevOps 订购发布阶段 - Azure DevOps ordering the release stages Azure DevOps 发布管道中的 Bicep - Azure Bicep in DevOps release pipeline 当在 yaml 管道配置中声明时,环境不会在 Azure Devops 中自动创建 - Environments are not automatically created in Azure Devops when declared in yaml pipeline config 如何通过 azure devops 发布管道设置 Azure 数据工厂警报和指标? - How to set up Azure Data Factory alerts & metrics via azure devops release pipelines?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM