【问题标题】:VSTS task input dataSourceBindings not workingVSTS 任务输入 dataSourceBindings 不起作用
【发布时间】:2019-03-05 07:04:31
【问题描述】:

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

这是我在扩展清单中的端点/数据源定义:

{
"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:

"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 上安装扩展以进行测试后,我在新服务端点下拉菜单中看到了可用的自定义服务类型。我为我的项目定义了一个新的设置正确的凭据。使用我定义的 TestConnection 数据源验证连接。

但是,当我查看我的构建任务之一时,应该用来自 dataSource ListApplication 的响应填充的选择列表是空的。

看来问题可能是我在dataSourceBinding中定义的胡子模板。这就是我应该从数据源中的 REST 调用中得到的:

[
   "A Customer Portal",
   "A Fine PHP Application",
   "A Simple Chess Game"
]

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

{"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、mustache 模板……我是瞎子。

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

【问题讨论】:

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


    【解决方案1】:

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

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

    "dataSourceBindings": [
        {
            "target": "kiuwanappname",
            "endpointId": "$(kiuwanConnection)",
            "dataSourceName": "ListApplications"
        }
    ]
    

    另一方面,没有办法调试它,只是可以在单击下拉列表控件时捕获请求。

    【讨论】:

    • 感谢您的回答。我已经尝试了您的建议,但仍然得到一个空的组合。还有其他想法吗?不知道后台发生了什么有点令人沮丧。
    • 您好starian chen,我的错误我没有更新任务版本,并且更改没有任何效果。有用!非常感谢
    • 顺便说一句,我找到了一种以某种方式调试它的方法。这是在starian回答中暗示的。使用浏览器中的开发人员工具,您可以看到对外部服务端点的调用和响应。当调用失败时,您会看到 TFS 错误消息并查看请求标头,您会看到有效负载。非常有帮助,感谢我看到我没有升级任务版本。
    • 即使是这里的文档也没有包含这些有价值的信息。谢谢。 docs.microsoft.com/en-us/rest/api/azure/devops/serviceendpoint/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多