【问题标题】:How do you add a checkbox input to an Azure DevOps Task Group?如何将复选框输入添加到 Azure DevOps 任务组?
【发布时间】:2020-02-24 12:11:34
【问题描述】:

在 Azure DevOps 中,我创建了一个使用 newman CLI 运行 Postman 测试的任务组。作为输入,用户可以传入 Postman 集合和环境文件的路径。

由于newman CLI 是必需的,因此任务组中的第一个任务是安装它。但是,在运行多个集合的情况下,无需反复安装 CLI,因此我想提供一个复选框,然后根据该复选框的值有条件地运行安装任务。

由于任务组的 UI 非常缺乏有用的选项,我开始探索 API。我可以添加额外的输入,但将明显的 type 选项设置为 checkbox 只会产生额外的文本 (string) 输入。

POST https://dev.azure.com/{org}/{project}/_apis/distributedtask/taskgroups?api-version=5.1-preview.1

{
    ...
    "inputs": [
        {
            "aliases": [],
            "options": {},
            "properties": {},
            "name": "Rbt.Cli.Install",
            "label": "Install 'newman' CLI?",
            "defaultValue": true,
            "required": false,
            "type": "checkbox",
            "helpMarkDown": "Choose whether or not to install the 'newman' CLI. You only need to install it if it hasn't already been installed by a previos task running on this job.",
            "groupName": ""
        },
        ...
    ],
    ...
}

仔细查看文档,有一个输入定义 - TaskInputDefinition。然而,看起来好像负责编写that documentation 的人有一天很早就离开了,而且从未有时间去做。根本没有描述,因此无法知道定义中属性的有效值。

如何向我的任务组添加复选框?

【问题讨论】:

标签: azure-devops azure-devops-task-groups


【解决方案1】:

我现在发现任务组提供picklist 作为输入类型。这允许向用户显示是/否选项,并且根据他们的回答,我可以有条件地运行任务。

不过,如果有人知道怎么做的话,我还是希望有一个复选框。

{
    "aliases": [],
    "options": {
        "yes": "Yes - install CLI",
        "no": "No - the CLI has already been installed"
    },
    "properties": {},
    "name": "Postman.Cli.Install",
    "label": "Install 'newman' CLI?",
    "defaultValue": "yes",
    "required": true,
    "type": "picklist",
    "helpMarkDown": "Choose whether or not to install the 'newman' CLI. You only need to install it if it hasn't already been installed by a previos task running on this job.",
    "groupName": ""
}

【讨论】:

    【解决方案2】:

    您可以通过将类型设置为boolean来轻松地将复选框添加到管道任务中

     {
        "name": "Rbt.Cli.Install",
        "type": "boolean",
        "label": "Install 'newman' CLI?"  
     }
    

    还可以根据复选框状态控制其他控件的可见性,如下所示:

    {
        "name": "someOtherField",
        "type": "string",
        "label": "Some other field",
        "visibleRule": "Rbt.Cli.Install = true"
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-29
      • 2020-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-07
      相关资源
      最近更新 更多