简体   繁体   English

[Azure 部署]:我们可以使用 c# 按名称过滤 Azure 资源组部署吗?

[英][Azure Deployments]: Can we filter Azure Resource Group Deployments by name using c#?

I am trying to fetch the Azure Resource Group Deployments by using filter where name starting with "Deploy" but can't find any documentation on the $filter.我正在尝试使用名称以“Deploy”开头的过滤器获取 Azure 资源组部署,但在 $filter 上找不到任何文档。

I tried to do something like below:我试图做如下的事情:

try
{
    var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
    var resourceClient = new ResourcesManagementClient(subscriptionId, credentials);
    var deployments = resourceClient.Deployments;
    AsyncPageable<DeploymentExtended> rgDeployments = deployments.ListByResourceGroupAsync("myRG", "name eq 'Deploy-20210412184314'");
    await foreach (DeploymentExtended deploymentProperties in rgDeployments)
    {
        Trace.WriteLine(deploymentProperties.Name);
    }
}
catch(Exception e)
{
    Trace.WriteLine(e.Message);
}

But it gives error saying -但它给出了错误说 -

{"error":{"code":"InvalidProvisioningStateFilter","message":"Invalid $filter 'name eq 'Deploy-20210412184314'' specified in the query string."}}

So can we only use filter like provisioningState eq '{state}' not for name?那么我们可以只使用像provisioningState eq '{state}'这样的过滤器而不是名称吗?

I am using Azure Resources Management client library for .NET .我正在为 .NET 使用 Azure 资源管理客户端库

Please refer this documentation .请参阅本文档

I am afraid you could not use the filter with name eq 'Deploy-20210412184314' , in this case, if you already knew the name of the deployment and want to get it at the resource group scope, no need to use ListByResourceGroupAsync , just use this method DeploymentsOperations.GetAsync(String, String, CancellationToken) , pass the resourceGroupName and deploymentName , you can simply get it.恐怕您不能使用name eq 'Deploy-20210412184314'的过滤器,在这种情况下,如果您已经知道部署的名称并想在资源组 scope 中获取它,则无需使用ListByResourceGroupAsync ,只需使用这个方法DeploymentsOperations.GetAsync(String, String, CancellationToken) ,传入resourceGroupNamedeploymentName ,就可以简单的获取了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM