json - 使用 Azure 发布管道在开发、阶段和生产槽上部署期间替换/更新 json 文件的值

标签 json azure-devops continuous-deployment azure-powershell azure-pipelines-release-pipeline

我是 Azure 新手,我的任务是在部署时更新 json 文件的值。我在 Azure 发布管道 Dev、Stage 和 Prod 中有 3 个部署槽。

我有以下 Json 文件需要更新。

"tables": [{
    "name": "CustomerContract",
    "columns": [{
               "name": "Year",
               "dataType": "int64",
               "sourceColumn": "Year",
               "summarizeBy": "none"
           },
           {
               "name": "<devname>",
               "dataType": "int64",
               "sourceColumn": "CustomerNumber",
               "summarizeBy": "none",
               "isHidden": <trueifdev>
           }
    ],
    "partitions": [{
        "name": "Partition",
        "dataView": "full"
    }]
  },
}

在上面的 json 文件中,我需要更新以下键的值。

  • “隐藏”
  • “姓名”

以上两个键的值根据插槽(Dev、Stage 和 Prod)而有所不同。

请帮我解决如何在部署时根据插槽更改/更新上述键的值?

以下链接在我的情况下不起作用,因为我的 json 文件属于共享点数据模型。

Azure Dev ops replace tokens per environment in release pipeline

最佳答案

Please help me out how can i change/update the values of above keys at deployment time based on slots?

如果构建时没有生成Json文件。我们仍然可以使用任务 Replace Tokens 来更新键的值。

作为测试,更改键值的定义:

"tables": [{
    "name": "CustomerContract",
    "columns": [{
               "name": "Year",
               "dataType": "int64",
               "sourceColumn": "Year",
               "summarizeBy": "none"
           },
           {
               "name": "#{DevName}#",
               "dataType": "int64",
               "sourceColumn": "CustomerNumber",
               "summarizeBy": "none",
               "isHidden": #{trueifdev}#
           }
    ],
    "partitions": [{
        "name": "Partition",
        "dataView": "full"
    }]
  },
}

.json 文件中变量的格式为 #{DevName}# & #{trueifdev}#

将此文件复制到工件并使用替换 token 任务来更新 key 的值:

enter image description here

并根据阶段定义变量上的键值:

enter image description here

作为阶段阶段的测试结果:

       {
           "name": "TDev456",
           "dataType": "int64",
           "sourceColumn": "CustomerNumber",
           "summarizeBy": "none",
           "isHidden": False
       }

该键的值 nameisHidden 已更新为 TDev456False

希望这有帮助。

关于json - 使用 Azure 发布管道在开发、阶段和生产槽上部署期间替换/更新 json 文件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57552329/

相关文章:

azure - 如何在 azure 订阅 API 中设置 header ?

json - 在 golang 中存储和检索接口(interface)

javascript - 将数据从 .json 文件导入到 Brain.js 神经网络

javascript - 如何删除 JSON 数组中的数据?

azure - 使用 Azure CLI (2.0.23) 创建函数应用程序无法链接到部署源 url

msbuild - 是否可以使用 dotnet CLI 提取 csproj 文件中元素的值?

javascript - 使用 AngularJS 将隐藏值传递给 JSON

azure - 如何在 azure-pipelines.yml 中使用 AzureCLI 删除 Azure Blob 存储上的旧文件

typescript - cdk CI/CD 管道 - 销毁重复堆栈

azure - 当我进行部署槽交换时,为什么 azure 会重新启动网站?