【问题标题】:How to display "Area path" in VSTS build task input PickList?如何在 VSTS 构建任务输入 PickList 中显示“区域路径”?
【发布时间】:2017-04-09 14:59:06
【问题描述】:

我需要在 VSTS 构建任务输入 PickList 中显示“区域路径”,以便我可以从构建任务中检索用户选择的“区域路径”值并将其设置在构建任务生成的工作项中.现有的 VSTS API 可以做到这一点吗?如果是这样怎么做?

我认为这是在实用程序部分的复制文件任务中完成的。

提前致谢。

【问题讨论】:

  • 您可以定义sourceDefinitions来调用服务(例如REST API)来获取必要的数据并将数据绑定到dataSourceBindings中对应的picklist。但是找不到获取当前团队项目 URL 的方法?你能让用户指定团队项目的 URL 吗?
  • @starain-MSFT:我不能让用户输入项目名称,也不能使用 VSTS 凭据指定单独的端点来获取此数据。 (如您发送的示例链接)谢谢。

标签: tfs azure-devops azure-pipelines azure-pipelines-build-task azure-devops-rest-api


【解决方案1】:

是的,是的。您可以在 task.josn 文件中添加以下部分来实现此目的:

  "inputs": [
    {
      "name": "rootArea",
      "type": "pickList",
      "label": "rootArea",
      "defaultValue": "",
      "required": false,
      "helpMarkDown": "Select the root area.",
      "properties": {
                "DisableManageLink": "True"
            }   
    },
    {
      "name": "childArea",
      "type": "pickList",
      "label": "childArea",
      "defaultValue": "",
      "required": false,
      "helpMarkDown": "Select the child area.",
      "properties": {
                "DisableManageLink": "True"
            }   
    }
  ],
  "sourceDefinitions": [
        {
            "target": "rootArea",
            "endpoint": "/$(system.teamProject)/_apis/wit/classificationNodes/areas?$depth=2&api-version=1.0",
            "selector": "jsonpath:$.name",
            "keySelector": "jsonpath:$.name",
                "authKey": "tfs:teamfoundation"
        },
        {
            "target": "childArea",
            "endpoint": "/$(system.teamProject)/_apis/wit/classificationNodes/areas?$depth=2&api-version=1.0",
            "selector": "jsonpath:$.children[*].name",
            "keySelector": "jsonpath:$.children[*].name",
                "authKey": "tfs:teamfoundation"
        }
    ],

你会得到这样的构建任务:

但是,由于classification nodes api的响应中的数据结构,当子区域的级别越多时,您必须添加更多的输入。

【讨论】:

  • 谢谢 Eddie,这正是我想要的。
  • 是否可以使用 vso-node-api 获得这个?
  • @Bandara 是的,在 WorkItemTrackingApi 中使用 getClassificationNode() 方法。
  • 我在使用 getClassificationNode() 时遇到以下错误 [错误:请求失败:错误请求 (400) - xxxxx.visualstudio.com/MyFirstProject/_apis/wit/… statusCode: 400 以下是代码示例,var areaPath = "MyFirstProject\Area1Test "; this.vstsWI.getClassificationNode(this.projName, wi.TreeStructureGroup.Areas, areaPath).then((nodex: wi.WorkItemClassificationNode) => { console.log(nodex); }).catch((e) => { console .error(e); });
  • @Bandara 似乎“TreeStructureGroup.Areas”存在一些问题,该值未应用于其余 api 调用。并且您不需要在区域路径中指定根区域。因此,现在使用此代码作为解决方法: var areaPath = "Areas\\Area1Test"; this.vstsWI.getClassificationNode("MyFirstProject", null, areaPath).then((nodex: wi.WorkItemClassificationNode) => { console.log(nodex); }).catch((e) => { console.error(e ); });
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-15
  • 2017-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多