使用 task.json 中的 Web API 来填充选择列表 buildtask [英] Using a web API in task.json to fill picklists buildtask
问题描述
我是第一次 TFS/VSTS 扩展开发人员.我当前的任务是构建一个简单的 VSTS Build 任务.
I am a first time TFS/VSTS extension developer. My Current task is to build a simple VSTS Build task.
我们有一个包含产品信息的自制 Web API,但我被困在源代码绑定中.已找到有关使用端点服务的信息,但未填充我的选择列表.
We have a self made web API containing product information, but I am stuck in source binding. Found information about using the endpoint service, but my picklist aren't populated.
到目前为止我所拥有的:
What i have so far:
任务.Json
"inputs": [
{
"name": "APIURL",
"type": "connectedService:Generic",
"label": "API URL",
"required": true,
"GroupName": "WebAPIsettings",
"helpMarkDown": ""
},
{
"name": "List1",
"type": "pickList",
"label": "List1",
"defaultValue": "",
"required": true,
"GroupName": "WebAPIsettings",
"helpMarkDown": ""
},
{
"name": "List2",
"type": "pickList",
"label": "List2",
"defaultValue": "",
"required": true,
"GroupName": "WebAPIsettings",
"helpMarkDown": ""
}]
,"sourceDefinitions": [
{
"target": "List1",
"endpoint": "/api/data/get",
"selector": "jsonpath:$.[Code]",
"authKey": "$(APIURL)"
},
{
"target": "List2",
"endpoint": "/api/data/get",
"selector": "jsonpath:$.[ID]",
"authKey": "$(APIURL)"
}]
我创建了一个指向 API 的通用端点 (http://sample.api.local)
I've created an generic endpoint that points towards the API (http://sample.api.local)
选择端点后,list1 和 list2 都没有填充,所以我遗漏了一些东西.
Both list1 and list2 are not populated after selecting the endpoint, so i'm missing something.
我已经用 http://jsonpath.com/ 测试了我的 API json 输出JSON 测试数据:
I've tested my API json output with http://jsonpath.com/ JSON test data:
[{"Code":"0344","ID":"version1"},
{"Code":"0363","ID":"version2"},
{"Code":"0518","ID":"version3"},
{"Code":"0599","ID":"version4"}]
我错过了什么?
推荐答案
改用此代码:
"selector": "jsonpath:$[*].ID"
这篇关于使用 task.json 中的 Web API 来填充选择列表 buildtask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!