[英]In azure devops: how can I inject my pipeline variables as appsettings when deploying a docker container to azure?
I'm having trouble setting my appsettings in a deployed docker container on azure.我在 azure 上部署的 docker 容器中设置我的应用设置时遇到问题。
My setup:我的设置:
I need to deploy the image to multiple environments.我需要将映像部署到多个环境。 Every environment has different appsettings.
每个环境都有不同的应用程序设置。 I defined the variables in my pipeline "variables tab":
我在管道“变量选项卡”中定义了变量:
And I need to send these to my azure so they can be used.
我需要将这些发送到我的 azure 以便它们可以使用。
When I manually add them it works, but i want to extract them from my variables, so I only have to add them once.当我手动添加它们时它可以工作,但我想从我的变量中提取它们,所以我只需要添加一次。 (see screenshot 1)
(见截图1)
Edit: The screenshot above works.
编辑:上面的截图有效。 But this is not what I'm looking for.
但这不是我要找的。 As I'd have to edit the appsettings pipeline each time I add or remove a new appsetting.
因为每次添加或删除新的 appsetting 时我都必须编辑 appsettings 管道。 Also I believe that removing an appsetting here will just leave it on the deployed environment.
此外,我相信在此处删除 appsetting 只会将其保留在已部署的环境中。
I'm deploying an existing docker image, so i'm unable to edit the appsetting.json file.我正在部署现有的 docker 映像,因此无法编辑 appsetting.json 文件。 I also won't make different docker files for each environment.
我也不会为每个环境制作不同的 docker 文件。
Is there a way to achieve this?有没有办法实现这一目标? How can I extract / list the variables defined in my pipeline as docker variables or appsettings?
如何提取/列出我的管道中定义的变量作为 docker 变量或 appsettings?
You can define pipeline variables in your pipeline and have them attached to a specific scope (read stage) or the release scope (applied to all stages).您可以在管道中定义管道变量,并将它们附加到特定范围(读取阶段)或发布范围(适用于所有阶段)。
Eg I have a variable defined as EnvironmentConnectionString
which is defined in two scopes:例如,我有一个定义为
EnvironmentConnectionString
的变量,它定义在两个范围内:
Then you can set this up in your "Application and Configuration Settings" like然后您可以在“应用程序和配置设置”中进行设置,例如
- ConnectionString $(EnvironmentConnectionString)
- Logging $(logging_flag)
Note the $(variable name) syntax for using these variables注意使用这些变量的 $(variable name) 语法
When the different stages of the pipeline run, they automatically pick up the values specific to the stage and apply to azure app settings.当管道的不同阶段运行时,它们会自动选取特定于该阶段的值并应用于 azure 应用程序设置。
You can have different variable groups for different stages.您可以为不同的阶段设置不同的变量组。 These Variable Groups should have same variables defined with different values.
这些变量组应该具有定义为不同值的相同变量。
For example: The Dev
Variable Group and Release
group both have variables Port
, RequestTimeout
... The Port
in Dev
is 4999 while the Port
in Release
could be 5000. We can link these groups to specific Stage scope, Dev
variable group for Dev
stage and Release
group for Release
stage.举个例子:
Dev
变集团和Release
集团都有变数Port
, RequestTimeout
...该Port
的Dev
是4999,而Port
的Release
可能是5000,我们可以链接这些组特定的舞台范围, Dev
变量组Dev
阶段和Release
阶段的Release
组。
[![enter image description here][1]][1] [![在此处输入图像描述][1]][1]
Make sure all your stages have same settings like this, and then the variables with be replaced with correspondings values for different scopes.确保所有阶段都具有相同的设置,然后将变量替换为不同范围的相应值。
Update:更新:
Each stage in the pipeline is independent , they represent different environments.管道中的每个阶段都是独立的,它们代表不同的环境。 So we have to define the settings of stage or settings of the tasks within the stages one by one.
所以我们必须一一定义阶段的设置或阶段内任务的设置。 We have to define the
appsettings
input one by one.我们必须
appsettings
定义appsettings
输入。 [1]: https://i.stack.imgur.com/ukbjs.png [1]: https : //i.stack.imgur.com/ukbjs.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.