Cannot use resultSelector while developing an Azure DevOps extension

366 views Asked by At

I am working on a custom extension for Azure Devops which already contains a service endpoint:

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

In addition, I would like to create a custom Release Artifact Source:

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

Following this documentation, my current struggle is in filling the fields under the Artifact Source using an external API. I tried many patterns in the following ‘resultSelector’ and ‘resultTemplate’, but couldn’t hit one that worked for me.

In my example, I would like to take all the ‘uri’ values under ‘builds’ in the json response and present them in the ‘definition’ inputDescriptor of the Artifact Source. All my attempts resulted in an empty combo-box, even though I can see the request reaching the required API.

The json I would like to parse into the combo-box:

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

Can you please help me create the Mustache pattern to retrieve the above "uri" values?
I tried:

$.builds[*].uri

which doesn't seem to work.

Here's some more information in case it helps.

Service endpoint's datasources:

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

Artifact source:

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

Any help provided will be highly appreciated.

1

There are 1 answers

0
Bar Belity On

The working combination for this case is:

dataSources:

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

dataSourceBindings:

{
  "target": "definition",
  "dataSourceName": "BuildNames",
  "resultTemplate": "{ \"Value\" : \"{{{uri}}}\", \"DisplayValue\" : \"{{{uri}}}\" }"
}