且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将现有(整个)Azure DevOps 管道迁移到基于 YAML 的管道(批量)

更新时间:2023-11-04 10:23:34

到现在为止,我们所支持的就是你所看到的,使用View YAML来复制/粘贴代理作业的定义.获取一个管道的整个定义还有另一种解决方法是使用 API 从构建定义中获取 JSON将其转换为 YAML,调整语法,然后如果需要,更新引用的任务.

  • 首先,使用

    • 将 YAML 复制到 Azure Devops 的 YAML 编辑器.然后最重要的一步是调整语法.

    用任务名称版本替换refName键值.为此,您可以访问我们在 github 中打开的 tasks 源代码,内置任务可以在那里找到(注意:请查看对应任务的task.json文件)

    注意:使用此方法还有一个缺点,即您需要非常熟悉 YAML 语法,以便您可以调整从 JSON 成功转换的内容.

    I would like to move the existing Azure DevOps pipelines to YAML based for obvious advantages. The problem is there are many of these and each one has many jobs.

    When I click around in Azure DevOps, the "View YAML" link only appears for one job at a time. So that's gonna be a lot of manual work to view YAMLs for each pipeline x jobs and move that to code.

    But for each pipeline there seems to be a way to "export" the entire pipeline in json. I was wondering if there is a similar way to at least dump the entire pipeline as YAML if not an entire folder.

    If there is an API which exports the same then even better.

    Until now, what we supported is what you see, use View YAML to copy/paste the definition of agent job. There has another workaround to get the entire definition of one pipeline is use the API to get the JSON from a build definition, convert it to YAML, tweak the syntax, then if needed, update the tasks which are referenced.

    • Copy the YAML to a YAML editor of Azure Devops. Then the most important step is tweak the syntax.

    Replace the refName key values with task names and version. For this, you can go our tasks source code which opened in github, built in tasks can be found there(note: please see the task.json file of corresponding task)

    Noted: Use this method has another disadvantage that you need very familiar with YAML syntax so that you can tweak the content which convert from JSON successfully.