根据Azure Devops中的文件路径类型动态填充选择列表?

时间:2018-12-21 11:12:23

标签: azure-devops azure-pipelines azure-pipelines-build-task picklist

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

.. WHERE id IN (1,2,3,...)

1 个答案:

答案 0 :(得分:1)

开箱即用的任务是开源的,因此您可以浏览repository以获得有关它们使用的模式的一些想法。这是来自Download Build Artifacts task的示例。构建定义取决于所定义的项目。

{
        "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}}}\"}"
    },