Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

tfs - Using a web API in task.json to fill picklists buildtask

I am a first time TFS/VSTS extension developer. My Current task is to build a simple VSTS Build task.

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:

Task.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)"
}]

I've created an generic endpoint that points towards the API (http://sample.api.local)

Both list1 and list2 are not populated after selecting the endpoint, so i'm missing something.

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"}]

What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using this code instead:

"selector": "jsonpath:$[*].ID"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...