如何通过 VS Code 在 Azure DevOps YAML 文件中添加和验证自定义构建任务

How to add and validate custom build task in Azure DevOps YAML File via VS Code

我有包含构建任务的 Azure DevOps 自定义扩展。我正在尝试 configure/edit 我的代码库中的 YAML 文件,并通过 VS 代码将我的自定义构建任务添加到其中。我正在使用 Microsoft VS Code 扩展 docs-yaml 扩展来验证我的 YAML 文件。

正如您在下图中看到的,Microsoft Build 模板中可用的所有构建任务均已成功验证,没有任何问题。但它未能验证我的构建任务 sampletask@3。据我了解,YAML 文件正在针对名为管道架构的文件进行验证。我在下面的位置找到了这个模式文件 https://raw.githubusercontent.com/microsoft/azure-pipelines-vscode/v1.174.2/service-schema.json

  1. 如何/是否可以将我的构建任务详细信息添加到管道架构文件中?
  2. 如果以上不可能,有什么方法可以在 VS Code 中成功验证我的构建任务?

请参考下图。

参考资料:

How to add and validate custom build task in Azure DevOps YAML File via VS Code

我无法使用扩展名 docs-yaml 重现此问题。

然后我测试另一个常用的扩展Azure Pipelines,我可以像你一样重现这个问题。所以我大胆假设这个验证应该来自扩展的Azure Pipelines。您可以检查您是否在 Visual Studio 代码中安装了此扩展程序。

安装该扩展并重启 VS Code 后,我可以看到验证信息:

要解决这个问题,我们可以继续文档Azure Pipelines for VS Code

Out of the box, the extension has a generic schema file that includes only in-box tasks. You probably have custom tasks installed in your organization. To teach the extension about those, grab a copy of your schema and tell the extension where to find it.

  1. Visit https://dev.azure.com/YOU-ORG-HERE/_apis/distributedtask/yamlschema and save the output as my-schema.json.
  2. Edit your workspace's settings.json to include this: {
    "[azure-pipelines].customSchemaFile": "./path/to/my-schema.json" }
  3. Restart VS Code. The extension will now validate against your schema. It'll give you autocompletes for your custom tasks.

第二步的详细步骤:

点击你的VS代码左下角的齿轮按钮,Manage-> Settings,然后点击Workspace->Extensions->Azure pipeline:

我将yamlschema.json文件保存在settings.json所在的文件夹中。

重启 VS Code 后,我可以在 VS Code 中成功验证构建任务: