首页 > 解决方案 > 无法在 Azure DevOps 2019 通过代码(无权限)创建代理池

问题描述

我问有关通过 c# 创建代码的问题:this

所以,我的代码是:

var _tfsUrl = "http://mytfs.domain.local:8080/tfs/Collection_Name/";
VssCredentials c = new VssCredentials(new WindowsCredential());

using (var connection= new VssConnection(new Uri(_tfsUrl), c))
{
 var client = connection.GetClient<TaskAgentHttpClient>();
 var agentPools = client.GetAgentPoolsAsync().Result;
 var result = client.AddAgentPoolAsync(new TaskAgentPool("Auto test pool_1")).Result;  //error !
}

但我没有权限:

 System.AggregateException: 'Web method running: [http://mytfs.domain.local:8080/tfs/Collection_Name/_apis/distributedtask/pools] (POST)pools[distributedtask] E2EId: some_uid'

 AccessDeniedException: Access denied. 'UserName' needs Manage permissions to perform the action. For more information, contact the Azure DevOps Server administrator.

所以,我尝试手动创建代理池,它可以工作!

我的用户名在“代理池-> 安全”中具有管理权限。

我的角色是:构建管理员、项目管理员、发布管理员。

你能告诉我,如何解决这个问题吗?谢谢!

标签: c#azure-devopsazure-devops-rest-api

解决方案


您的代码正在尝试在项目集合级别创建代理池。

必须通过导航到组织设置中的代理池页面来确保您是所有代理池中具有管理员角色的组的成员。

在此处输入图像描述

此外,您还可以尝试在代码片段中使用用户的 PAT 令牌(完全访问权限)进行身份验证。

如果以上所有方法仍然不起作用,只需将您的用户添加到“项目集合管理员”组中,这应该可以解决问题。


推荐阅读