如何在内联数据源绑定中使用endpointUrl?

时间:2017-01-16 15:05:40

标签: azure azure-pipelines-build-task azure-pipelines-release-pipeline

我正在编写自定义任务以将文档发布到Azure API门户。我希望任务的UI列出所选订阅和资源组的可用API管理服务。根据{{​​3}},这在技术上应该可以通过指定与我的数据源绑定内联的endpointUrl来实现。我尝试在Azure RM Web部署任务中的数据源之后对端点进行建模,但我似乎无法使其正常工作。在我的任务中,我可以选择我的订阅,选择我的资源组,但我的自定义数据源的pickList始终为空。我在任务定义中没有做任何明确的身份验证,所以我不确定这是否与某种程度相关。以下是我的任务的inputsdataSourceBindings

"inputs": [
    {
        "name": "ConnectedServiceName",
        "type": "connectedService:AzureRM",
        "label": "Azure RM Subscription",
        "defaultValue": "",
        "required": true,
        "helpMarkDown": "Select the Azure Resource Manager subscription for the deployment."
    },
    {
        "name": "ResourceGroupName",
        "label": "Resource Group",
        "type": "pickList",
        "required": true,
        "helpMarkDown": "Select resource group which contains the API portal"
    },
    {
        "name": "ApiPortalName",
        "type": "pickList",
        "label": "API Portals",
        "defaultValue": "",
        "required": true,
        "properties": {
            "EditableOptions": "True"
        },            
        "helpMarkDown": "Select the Azure Resource Manager subscription for the deployment."
    }
],
"dataSourceBindings": [
    {
        "target": "ResourceGroupName",
        "endpointId": "$(ConnectedServiceName)",
        "dataSourceName": "AzureResourceGroups"
    },
    {
      "name": "ApiPortals",
      "target": "ApiPortalName",
      "endpointId": "$(ConnectedServiceName)",
      "endpointUrl": "https://management.azure.com/subscriptions/$(endpoint.subscriptionId)/resourceGroups/$(ResourceGroupName)/providers/Microsoft.ApiManagement/service?api-version=2016-07-07",
      "resultSelector": "jsonpath:$.value[*].name",
      "parameters": {
          "ResourceGroupName": "$(ResourceGroupName)"
      }
    }

更新

在Chrome中检查控制台后,我收到一条错误消息,指出我无法调用不以{{endpoint.url}}开头的网址。我在根目录下使用{{endpoint.url}}更新了我的任务,我确实看到它尝试进行我预期的API调用:

    {
      "name": "ApiPortals",
      "target": "ApiPortalName",
      "endpointId": "$(ConnectedServiceName)",
      "endpointUrl": "{{endpoint.url}}/subscriptions/$(endpoint.subscriptionId)/resourceGroups/$(ResourceGroupName)/providers/Microsoft.ApiManagement/service?api-version=2016-07-07",
      "resultSelector": "jsonpath:$.value[*].name",
      "parameters": {
          "ResourceGroupName": "$(ResourceGroupName)"
      }
    }

现在的问题是,出于某种原因,endpoint.url解析为Azure RM端点类型的https://management.core.windows.net。 Azure RM API托管在https://management.azure.com。因此,我收到403,因为我的端点凭据是针对Azure RM服务主体的,而不是Azure经典管理API。

我也用这些信息更新了我的this issue。我相信这是一个错误,Azure RM服务端点的endpoint.url应解析为https://management.azure.com。如果查看Azure RM服务端点中定义的数据源,它们都会引用https://managemnet.azure.com而非https://management.core.windows.net托管的API。

1 个答案:

答案 0 :(得分:1)

检查Custom build task JSON schema,你不能使用" endpointUrl"和" resultSelector" for" dataSourceBindings"在task.json中。用于在vss-extension.json文件中定义自定义服务端点。你也错过了" dataSourceName"为" ApiPortals"。

如果要使用URL调用Rest API并使用task.json中的选择器,则可以使用" sourceDefinitions"而不是" dataSourceBindings"。有关详细信息,请参阅this question中的答案。但是," sourceDefinitions"仅支持基本身份验证。就目前而言,这意味着这也不适用于你的场景。

因此,您需要创建自定义服务端点以实现目前所需的功能。