如何参数化Azure DevOps部署YAML管道以部署到多个环境
我有一个Azure DevOps部署YAML管道,该管道可创建Azure App服务并将代码部署到它。实际管道更为复杂,但是我正在简化此问题。
当前,我的管道可以成功部署到特定的Azure订阅(服务连接器),并具有变量中定义的资源名称。
我需要对管道进行参数化,以便它可以使用多个服务连接器部署到几个不同的环境(意味着Azure订阅)。每个环境都有不同的Azure资源命名约定。
有什么方法可以从XML或JSON文件中读取管道变量的值?这样,我可以为每个环境拥有多个配置文件,并将它们作为存储库的一部分存储。
这是多环境部署管道配置的正确方法吗?
I have an Azure DevOps Deployment YAML Pipeline that creates an Azure App Service and deploys code to it. The actual pipeline is more complex, but I am simplifying it for this question.
Currently my pipeline can successfully deploy to a specific Azure Subscription (Service Connector) with resource names defined in variables.
I need to parametrize the pipeline so that it can deploy to several different environments (means Azure Subscriptions) using multiple Service Connectors. Each environment has a different Azure Resource naming convention.
Is there any way to read the value of pipeline variables from an XML or JSON file? This way I can have multiple config files for each environment and store them as part of my repository.
Is this a right approach for multi-environment deployment pipeline configuration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用变量模板。还有另一个有趣的链接:了解有关使用模板可变重复使用的更多信息。
在这里,我有这个平坦的文件夹结构(为了清楚示例的清晰度):
因此,我们正在尝试运行
可重复使用的
job deploly-app.job.yaml,带有不同的变量集。我已经在每个
变量中定义了一些变量。{env} .yaml
文件deploy-app.job.yaml
文件接受一个允许注入变量模板的参数:在主管道中,我可以创建不同的阶段并注入所需的Vairable:
根据您的需求,您可以添加多个变量模板,具有命名约定等。确实取决于您,并取决于管道的复杂性。
You can use variable templates. There is another interesting link: Learn more about variable reuse with templates.
Here I have this flat folder structure (for the clarity of the sample):
So here we're trying to run the
reusable
job deploy-app.job.yaml with different variable sets.I've defined some variables in each
variable.{env}.yaml
filesThe
deploy-app.job.yaml
file accepts a parameter that allow to inject a variable template:In the main pipeline, I can create different stages and inject the desired vairables:
Based on your needs, you can add multiple variable templates, having a naming convention etc. Really up to you and depends on the complexity of your pipelines.
通过使用XML变换,我们可以执行操作。检查以下链接以获取完整的步骤。
https://www.dragonspears.com/博客/操作方向 - 连续访问 - 跨度 - 元素环境
上面提到的链接中提到的相同步骤。
By using XML transformation, we can perform the operation. Check the below link to get the complete steps.
https://www.dragonspears.com/blog/how-to-handle-continuous-deployment-across-multiple-environments
The same steps mentioned here are available in the link mentioned above.