5

我正在为 Azure Devops 开发一个自定义扩展,它已经包含一个服务端点:

"type": "ms.vss-endpoint.service-endpoint-type"

另外,我想创建一个自定义的 Release Artifact Source:

“type”: “ms.vss-releaseartifact.release-artifact-type”

按照这个文档,我目前的努力是使用外部 API 填充 Artifact Source 下的字段。我在以下“resultSelector”和“resultTemplate”中尝试了许多模式,但无法找到适合我的模式。

在我的示例中,我想在 json 响应中的 'builds' 下获取所有 'uri' 值,并将它们呈现在工件源的 'definition' inputDescriptor 中。我所有的尝试都导致了一个空的组合框,即使我可以看到请求到达了所需的 API。

我想解析到组合框中的 json:

{
"builds": [
    {
        "uri": "/build1",
        "lastStarted": "2018-11-07T13:12:42.547+0000"
    },
    {
        "uri": "/build2",
        "lastStarted": "2018-11-09T15:40:30.315+0000"
    },
    {
        "uri": "/build3",
        "lastStarted": "2018-11-12T17:46:24.805+0000"
    }
],
"uri": "https://<server-address>/api/build"
}

您能帮我创建 Mustache 模式来检索上述“uri”值吗?
我试过了:

$.builds[*].uri

这似乎不起作用。

如果有帮助,这里有一些更多信息。

服务端点的数据源:

"dataSources": [
                {
                  "name": "TestConnection",
                  "endpointUrl": "{{endpoint.url}}/api/plugins",
                  "resourceUrl": "",
                  "resultSelector": "jsonpath:$.values[*]",
                  "headers": [],
                  "authenticationScheme": null
                },
                {
                  "name": "BuildNames",
                  "endpointUrl": "{{endpoint.url}}/api/build",
                  "resultSelector": "jsonpath:$.builds[*].uri"
                },
                {
                  "name": "BuildNumbers",
                  "endpointUrl": "{{endpoint.url}}/api/builds/{{definition}}",
                  "resultSelector": "jsonpath:$.buildsNumbers[*].uri"
                }
]

神器来源:

"inputDescriptors": [
     {
       "id": "connection",
       "name": "Artifactory service",
       "inputMode": "combo",
       "isConfidential": false,
       "hasDynamicValueInformation": true,
       "validation": {
            "isRequired": true,
            "dataType": "string",
            "maxLength": 300
       }
     },
     {
       "id": "definition",
       "name": "definition",
       "description": "Name of the build.",
       "inputMode": "combo",
       "isConfidential": false,
       "dependencyInputIds": [
             "connection"
       ],
       "validation": {
            "isRequired": true,
            "dataType": "string",
            "maxLength": 300
        }
      },
      {
        "id": "buildNumber",
        "name": "Build Number",
        "description": "Number of the build.",
        "inputMode": "combo",
        "isConfidential": false,
        "dependencyInputIds": [
            "connection"
         ],
        "validation": {
             "isRequired": true,
             "dataType": "string",
             "maxLength": 300
        }
       }
],
"dataSourceBindings": [
   {
       "target": "definition",
       "dataSourceName": "BuildNames",
       "resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
    },
    {
       "target": "versions",
       "dataSourceName": "BuildNumbers",
       "resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
    },
    {
       "target": "latestVersion",
       "dataSourceName": "BuildNumbers",
       "resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
    },
    {
       "target": "artifactDetails",
       "resultTemplate": "{ Name: \"{{version}}\", downloadUrl : \"{{endpoint.url}}\" }"
    },
    {
       "target": "buildNumber",
       "dataSourceName": "BuildNumbers",
       "resultTemplate": "{ Value : \"{{uri}}\", DisplayValue : \"{{uri}}\" }"
    }
  ]
 }

提供的任何帮助将不胜感激。

4

1 回答 1

0

这种情况下的工作组合是:

数据源:

{
  "name": "BuildNames",
  "endpointUrl": "{{endpoint.url}}/api/build",
  "resultSelector": "jsonpath:$.builds[*]"
}

数据源绑定:

{
  "target": "definition",
  "dataSourceName": "BuildNames",
  "resultTemplate": "{ \"Value\" : \"{{{uri}}}\", \"DisplayValue\" : \"{{{uri}}}\" }"
}
于 2018-11-22T09:25:37.583 回答