Admiral Land
Admiral Land

Reputation: 2492

Can not create Agent Pool by code (no permissions) at Azure DevOps 2019

I ask question about create code via c#: this.

So, my code is:

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 !
}

But i have no permissions:

 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.

So, i try to create agent pool manually and it works!

My usernname have administration rights in 'Agent Pools-> Security'.

My roles are: Build Administrators, Project Administrators, Release Administrators.

Can you tell me , how to resolve this? Thank you!

Upvotes: 2

Views: 1029

Answers (1)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51073

Your code are trying to create agent pool in project collection level.

Have to make sure you're a member of a group in All agent pools with the Administrator role by navigating to agent pools page in your organization settings.

enter image description here

Besides, you could also try to use PAT token (full access) of your user in your code snippet for authentication.

If all above is still not work, simply add your user in 'Project Collection Administrators' group, which should do the trick.

Upvotes: 2

Related Questions