Azure 替换管道发布任务中 Asp.net MVC 服务模型终结点的 token

标签 azure azure-devops azure-pipelines azure-pipelines-release-task

我的解决方案中有 10 多个项目。一个项目有一个名为 Variable.release.config 的配置文件,其中包含所有应用程序变量、连接字符串和其他 web.config 模块,需要用库中的 Azure 变量替换。该配置文件被所有项目使用。该解决方案有 Asp.net MVC 网站,它有自己的 web.config、web.release.config。我正在尝试从 Variable.release.config 进行 xml 转换变量,它正在转换 web.config 中的所有内容,但端点地址的客户端部分中的端点变量的值没有被替换。

之前我使用的是 Azure App Service Deploy,以下是其 YAML:

steps:

    - task: AzureRmWebAppDeployment@4
      displayName: 'Azure App Service Deploy: abc-tst'
      inputs:
        azureSubscription: 'ABC Technologies(XXXX-XXX-XXX-XXX-XXXXXX)'
        WebAppName: 'ABC-tst'
        deployToSlotOrASE: true
        ResourceGroupName: 'abc-tst'
        SlotName: T2
        packageForLinux: '$(System.DefaultWorkingDirectory)/$(Release.DefinitionName)/drop/ABC.Frontend.zip'
        enableXmlTransform: true
        enableXmlVariableSubstitution: true

它没有替换端点中的变量。我看到几篇文章说只有端点不能用xml转换替换我需要使用第三方工具来传输Replace Token

我尝试了以下步骤:

  1. 文件转换
  2. 替换 token
  3. Azure 应用服务部署

但是它没有替换 web.config 中的端点变量地址,尽管 xml 转换成功并且在日志中替换 token 已替换该变量的 token 。

读完这篇文章后,我修改了我的发布任务,如下图所示answer .

有什么方法可以替换端点地址中的变量值还是我遗漏了什么?

Azure release pipeline task

最佳答案

您确定您已完成所有配置吗?

我在发布管道中尝试了这个替换 token ,一切顺利。您确定正确配置了目标文件吗?

日志中有这样的输出吗?

2020-05-28T07:11:02.8850410Z replacing tokens in: D:\a\r1\a\repos\stackoverflow\38-endpoint-replace\Web.config
2020-05-28T07:11:02.9045428Z   1 tokens replaced out of 1
2020-05-28T07:11:02.9048164Z replaced 1 tokens out of 1 in 1 file(s) in 0.079 seconds.

请尝试添加此类 powershell 步骤以在替换 token 步骤之前和之后检查文件内容。

enter image description here

注意

请注意,我最后的建议是我将其保留在日志中。如果您有敏感数据,请在之后撤销它们或从文件中删除以进行测试。

关于Azure 替换管道发布任务中 Asp.net MVC 服务模型终结点的 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62043374/

相关文章:

azure - 仅与 Azure DevOps 一起使用的服务主体是否需要付费?

docker - 是否可以在 Azure DevOps Pipeline 中运行 GitHub Workflow Actions?

azure - 如何删除 Azure 中的 SQL 数据库?

Azure Worker 将无法连接到虚拟网络

azure - 使用 SQL 的 Cosmos DB 查询数组值

azure - 当构建工件上的 "pull request trigger"被禁用时,为什么构建会由于 PR(构建验证策略)触发发布?

c# - Azure 上的 Websocket 服务器

azure-devops - VSTS Rest API - 创建发布

visual-studio - 通过 REST API 发布变量 - Visual Studio Team Services

azure-devops - 在管道构建期间获取 sql server (express) azure devops