首页 > 解决方案 > 根据 Azure Devops 中的文件路径类型动态填充选项列表?

问题描述

在 Azure Devops 中,我正在使用构建任务构建一个扩展,其中输入选项列表字段依赖于另一个输入文件路径字段。当用户提供输入文件路径时,我想动态读取并使用新项目填充选项列表。我试图搜索和实施,但找不到方法。任何帮助或指导将不胜感激。我找到了下面的示例来帮助我获取静态值。

{
   "name": "action",
   "type": "pickList",
   "label": "Action",
   "defaultValue": "Publish",
   "required": true,
   "helpMarkDown": "Select the Action to perform",
   "options": {
     "Publish": "Publish Changes",
     "Script": "Script Changes",
     "DeployReport": "Generate Deployment Report"
   }
 }

标签: azure-devopsazure-pipelinesazure-pipelines-build-taskpicklist

解决方案


开箱即用的任务是开源的,因此您可以查看存储库以了解它们使用的模式。这是下载构建工件任务的示例。构建定义取决于定义的项目。

{
        "name": "project",
        "type": "pickList",
        "label": "Project",
        "defaultValue": "",
        "required": true,
        "visibleRule": "buildType == specific",
        "properties": {
            "EditableOptions": "True",
            "DisableManageLink": "True"
        },
        "helpMarkDown": "The project from which to download the build artifacts"
    },
    {
        "name": "definition",
        "aliases": [
            "pipeline"
        ],
        "type": "pickList",
        "label": "Build pipeline",
        "defaultValue": "",
        "required": true,
        "visibleRule": "buildType == specific",
        "properties": {
            "EditableOptions": "True",
            "DisableManageLink": "True",
            "IsSearchable": "True"
        },
        "helpMarkDown": "Select the build pipeline name"
    },

然后在 dataSourceBindings 部分相信它使用来自先前选择的目标作为参数输入。

"dataSourceBindings": [
    {
        "endpointId": "tfs:teamfoundation",
        "target": "project",
        "endpointUrl": "{{endpoint.url}}/_apis/projects?$skip={{skip}}&$top=1000",
        "resultSelector": "jsonpath:$.value[?(@.state=='wellFormed')]",
        "resultTemplate": "{ \"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{name}}}\" }",
        "callbackContextTemplate": "{\"skip\": \"{{add skip 1000}}\"}",
        "callbackRequiredTemplate": "{{isEqualNumber result.count 1000}}",
        "initialContextTemplate": "{\"skip\": \"0\"}"
    },
    {
        "endpointId": "tfs:teamfoundation",
        "target": "definition",
        "endpointUrl": "{{endpoint.url}}/{{project}}/_apis/build/definitions?api-version=3.0-preview&$top=500&continuationToken={{{continuationToken}}}&name=*{{name}}*&queryOrder=2",
        "resultSelector": "jsonpath:$.value[?(@.quality=='definition')]",
        "parameters": {
            "project": "$(project)",
            "name": "$(name)"
        },
        "resultTemplate": "{ \"Value\" : \"{{{id}}}\", \"DisplayValue\" : \"{{{name}}}\" }",
        "callbackContextTemplate": "{\"continuationToken\" : \"{{{headers.x-ms-continuationtoken}}}\"}",
        "callbackRequiredTemplate": "{{{#headers.x-ms-continuationtoken}}}true{{{/headers.x-ms-continuationtoken}}}",
        "initialContextTemplate": "{\"continuationToken\" : \"{{{system.utcNow}}}\"}"
    },

推荐阅读