gpt4 book ai didi

azure - 如何通过 Azure DevOps 管道为 Azure Service Fabric 应用程序设置环境变量

转载 作者:行者123 更新时间:2023-12-03 06:38:28 25 4
gpt4 key购买 nike

我们的团队有一个 Service Fabric 应用程序,该应用程序在 ServiceManifest.xml 文件中定义了一个名为 connectionString 的环境变量

  <!-- Code package is your service executable. -->
<CodePackage Name="Code" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>myMMAPI.exe</Program>
<WorkingFolder>CodePackage</WorkingFolder>
</ExeHost>
</EntryPoint>
<EnvironmentVariables>
<EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value=""/>
<EnvironmentVariable Name="connectionString" Value="Server=mydb.123abc.database.windows.net; Authentication=Active Directory Password; Encrypt=True; Database=mydevdb; User Id=myId;Password=****" />
</EnvironmentVariables>
</CodePackage>

然后我们可以在 Startup.cs 类中引用此环境变量。

Constants.ConnectionString = Environment.GetEnvironmentVariable("connectionString");

但是,我们需要在使用 Azure DevOps Pipeline 进行部署期间设置此环境变量,而不是硬编码到此 ServiceManifest.xml 文件中。

有没有办法在 Azure DevOps 中传递此环境变量,以便我们可以更改每个环境的连接字符串?

最佳答案

您可以通过管道中的此任务引入使用变量切换的 token : https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens

这些变量可以在管道中定义,也可以在单独的文件中定义。

关于azure - 如何通过 Azure DevOps 管道为 Azure Service Fabric 应用程序设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74693345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com