如何将YAML配置文件作为Azure DevOps发布管道的一部分进行转换。

huangapple go评论64阅读模式
英文:

How to transform yaml config file as part of Azure DevOps Release pipeline

问题

我正在尝试创建一个Azure DevOps发布管道,该管道将从构件中获取一些YAML配置文件,然后从变量中设置此文件中的字段,并最终部署转换后的文件到目标机器。

目前,我在设置YAML文件中的字段方面遇到了问题 - 找不到适用于此的任务。
标准的FileTransform任务无法处理YAML文件。

Magic Chunks扩展任务处理YAML文件并正确执行替换,但仅在Windows上工作,我的一些目标机器是Linux。此外,Magic Chunks在修改文件时会剥夺所有注释 - 这种行为非常不方便,因为源YAML文件包含许多有用的注释。

那么,在Azure DevOps发布管道中,有哪些任务(或工具)可以用于设置YAML文件中的数据?非常感谢您的帮助!

谢谢。

英文:

I'm trying to make Azure DevOps Release pipeline which will take some yaml config file from artifact, then set fields in this file from variables and finally deploy transformed file to target machine.

Currently I'm having trouble with setting fields in yaml file - can't find task for this.
Standard FileTransform task can't handle YAML files.

Magic Chunks extension task is handling yaml files and doing substitution correctly, but it works only on Windows, and some of my target machines are Linux. Also Magic Chunks strips all comments when modifying file - еhis behavior is very inconvenient as source yaml file has lots of useful comments.

So what task (or tool) can be used to set data in yaml files inside Azure DevOps Release pipeline? Any help is greatly appreciated!

Thanks.

答案1

得分: 2

我建议查看yq。你可能熟悉用于操作JSON文件的jq,而yq执行的是相同的任务,但用于YAML文件。

没有Azure DevOps任务包装器,所以我建议从一个普通的Shell任务中调用它。它在Linux和Windows上都可用,所以你不应该遇到任何问题。

英文:

I'd suggest looking at yq. You're probably familiar with jq for manipulating json files and yq is performing the same task for yaml files.

There is no Azure DevOps task wrapper for it, so I'd call it from a straight shell task. It works on both linux and windows, so you shouldn't have any problems.

huangapple
  • 本文由 发表于 2023年5月13日 15:53:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76241656.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定