首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >VSTS任务输入dataSourceBindings不工作

VSTS任务输入dataSourceBindings不工作
EN

Stack Overflow用户
提问于 2018-03-17 21:34:44
回答 1查看 544关注 0票数 0

我正在维护一个带有几个构建任务的VSTS/TFS扩展和一个带有一些dataSources的自定义服务端点类型。我需要构建任务中的一个输入是一个填充了来自服务端点中定义的dataSources之一的信息的pickList。

下面是我在扩展清单中的端点/dataSources定义:

代码语言:javascript
复制
{
"id": "kiuwan-service-endpoint",
"description": "Kiuwan servide endpoint to connect to the Kiuwan platform",
"type": "ms.vss-endpoint.service-endpoint-type",
"targets": [
    "ms.vss-endpoint.endpoint-types"
],
"properties": {
    "name": "kiuwan",
    "displayName": "Kiuwan Platform",
    "url": {
        "displayName": "Kiuwan URL",
        "value": "https://api.kiuwan.com",
        "helpMarkDown": "The Kiuwan Service Endpoint URL is always https://api.kiuwan.com"
    },
    "dataSources": [
        {
            "name": "TestConnection",
            "endpointUrl": "{{endpoint.url}}/info",
            "resultSelector": "jsonpath:$.username"
        },
        {
            "name": "ListApplications",
            "endpointUrl": "{{endpoint.url}}/apps/list",
            "resultSelector": "jsonpath:$.[*].name"
        }
    ],
    "authenticationSchemes": [
        {
            "type": "ms.vss-endpoint.endpoint-auth-scheme-basic",
            "inputDescriptors": [
                {
                    "id": "username",
                    "name": "Username",
                    "description": "This is your Kiuwan username",
                    "inputMode": "textbox",
                    "isConfidential": false,
                    "validation": {
                        "isrequired": true,
                        "dataType": "string"
                    }
                },
                {
                    "id": "password",
                    "name": "Password",
                    "description": "Yup! this is your Kiuwan password",
                    "inputMode": "passwordBox",
                    "isConfidential": true,
                    "validation": {
                        "isrequired": true,
                        "dataType": "string"
                    }
                }
            ]
        }
    ],
    "helpMarkdown": "<a href=\"https://www.kiuwam.com\" target=\"_blank\"><b>Learn More</b></a>"
    }
}

以下是task.json文件中相关的任务输入定义和关联的dataSourceBinding:

代码语言:javascript
复制
"inputs": [
{
    "name": "kiuwanConnection",
    "type": "connectedService:Kiuwan",
    "label": "Kiuwan Service",
    "defaultValue": "",
    "required": true,
    "helpMarkDown": "Kiuwan service connection"
},
{
    "name": "kiuwanappname",
    "type": "pickList",
    "label": "Available Kiuwan applications",
    "required": false,
    "visibleRule": "projectnameselector = kiuwanapp",
    "helpMarkDown": "Select an existing application in Kiuwan to associate results to."
}
],
"dataSourceBindings": [
    {
        "target": "kiuwanappname",
        "endpointId": "$(kiuwanConnection)",
        "dataSourceName": "ListApplications",
        "resultTemplate": "{{#.}}{\"Value\": \"{{.}}\",\"DisplayValue\": \"{{.}}\"},{{/.}}"
    }
]

在我本地的TFS 2017上安装扩展以进行测试后,我在New service endpoint下拉列表中看到了可用的自定义服务类型。我为我的项目定义了一个新的凭据,设置了正确的凭据。使用我定义的TestConnection dataSource验证连接。

然而,当我去查看我的一个构建任务时,它是空的,这个列表应该用来自dataSource ListApplication的响应填充。

似乎问题可能出在我在dataSourceBinding中定义的鼠标模板。这是我应该从dataSource中的REST调用中得到的:

代码语言:javascript
复制
[
   "A Customer Portal",
   "A Fine PHP Application",
   "A Simple Chess Game"
]

在应用jsonpath之后。使用dataSourceBinding中定义的模板从命令行运行mustache,我得到这样的结果(在这种情况下,我没有转义"):

代码语言:javascript
复制
{"Value": "A Customer Portal","DisplayValue": "A Customer Portal"},{"Value": "A Fine PHP Application","DisplayValue": "A Fine PHP Application"},{"Value": "A Simple Chess Game","DisplayValue": "A Simple Chess Game"},

这正是我所期望的。

你知道为什么这可能不起作用吗?有没有办法调试它?有没有办法知道是否正在对我的服务端点进行调用?除了任务和扩展清单json文件中可能存在的拼写错误之外,这里可能存在不同的故障点( REST调用jsonpath、八字胡模板……我还是个盲人。

我们非常感谢您能提供的任何帮助。best,J.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-19 15:06:01

首先,如果apps/list接口返回数组对象(如[{"name":"n1"},{"name":"n2"}]),则将jsonpath:$.[*].name替换为jsonpath:$[*].name

其次,REST API返回一个数组,您可以从dataSourceBindings中移除resultTemplate定义:

代码语言:javascript
复制
"dataSourceBindings": [
    {
        "target": "kiuwanappname",
        "endpointId": "$(kiuwanConnection)",
        "dataSourceName": "ListApplications"
    }
]

另一方面,没有办法调试它,只能在单击dropdownlist控件时捕获请求。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49336624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档