Как обновить пул агента заданий выпуска VSTS с помощью powershell - PullRequest
1 голос
/ 04 апреля 2019

Я пытаюсь обновить пул агента определения выпуска VSTS с помощью powershell. Возможность получить идентификатор агента и подробности определения выпуска.

Powershell:

$User = 'xxxx@software.com'
$PersonalAccessToken = 'xxxx'
$base64authinfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f  $User, $PersonalAccessToken)))
$vstsAccount = "software"
$resource = 'Enterprise'

#Get the Agent ID
$uri = "https://$vstsAccount.visualstudio.com/_apis/distributedtask/pools/"
$projects = Invoke-RestMethod -Method Get -ContentType application/json -Uri $uri -Headers @{Authorization=("Basic {0}" -f $base64authinfo)} | ConvertTo-Json
$projects = $projects | ConvertFrom-Json
Write-Host "Json Body :" $projects
$id = $projects.value | ? name -eq 'Hosted VS2017'
Write-Host "Agent Pool Id :" $id.id


#Get release definition details
$uri2 = "https://vsrm.dev.azure.com/$vstsAccount/$resource/_apis/release/definitions/860?api-version=5.0"
$projects2 = Invoke-RestMethod -Method Get -ContentType application/json -Uri $uri2 -Headers @{Authorization=("Basic {0}" -f $base64authinfo)} | ConvertTo-Json
$projects2 = $projects2 | ConvertFrom-Json
Write-Host "Json Body :" $projects2

Ответ:

@{
source=userInterface; 
revision=84; 
description=; 
createdBy=; 
createdOn=2019-02-15T07:27:04.357Z; 
modifiedBy=; 
modifiedOn=2019-04-04T17:27:30.487Z; 
isDeleted=False; 
variables=; 
variableGroups=System.Object[]; 
environments=System.Object[]; 
artifacts=System.Object[]; 
triggers=System.Object[]; 
releaseNameFormat=Release-$(rev:r); 
tags=System.Object[]; 
pipelineProcess=; 
properties=; 
id=860; 
name=JMeterReleaseJob; 
path=\; 
projectReference=; 
url=https://vsrm.dev.azure.com/software/18979a9c-xxxx-xxxx-xxxx-f3fa4a82df3c/_apis/Release/definitions/860; _links=
}

Идентификатор агента json:

"value":  [
                  {
                      "createdOn":  "2016-03-23T12:04:35.723Z",
                      "autoProvision":  true,
                      "autoSize":  true,
                      "targetSize":  null,
                      "agentCloudId":  null,
                      "createdBy":  null,
                      "owner":  null,
                      "id":  2,
                      "scope":  "3e93f9e6-xxxx-xxxx-xxxx-994d196e1121",
                      "name":  "Hosted",
                      "isHosted":  true,
                      "poolType":  "automation",
                      "size":  10
                  },
                  {
                      "createdOn":  "2017-03-21T00:40:47.527Z",
                      "autoProvision":  true,
                      "autoSize":  true,
                      "targetSize":  null,
                      "agentCloudId":  null,
                      "createdBy":  null,
                      "owner":  null,
                      "id":  4,
                      "scope":  "3e93f9e6-xxxx-xxxx-xxxx-994d196e1121",
                      "name":  "Hosted VS2017",
                      "isHosted":  true,
                      "poolType":  "automation",
                      "size":  10
                  },
                  {
                      "createdOn":  "2018-05-04T10:20:59.69Z",
                      "autoProvision":  false,
                      "autoSize":  true,
                      "targetSize":  null,
                      "agentCloudId":  null,
                      "createdBy":  "@{displayName=Kabir Sharan; url=https://spsprodweu3.vssps.visualstudio.com/A3e42757e-xxxx-xxxx-xxxx-ee414eb0f5b1/_apis/Identities/8fe521c4-xxxx-xxxx-xxxx-6ca5f1b30c10; _links=; 
id=8fe521c4-xxxx-xxxx-xxxx-6ca5f1b30c10; uniqueName=Kabir@software.com; imageUrl=https://condecosoftware.visualstudio.com/_apis/GraphProfile/MemberAvatars/aad.OGZlNTIjhhLWFlZTgtNmNhNWYxY
jMwYzEw; descriptor=aad.OGZlNTIxYzQtYmQwNygtNmNhNWYxYjMwYzEw}",
                      "owner":  "@{displayName=Kabir Sharan; url=https://spsprodweu3.vssps.visualstudio.com/A3e42757e-xxxx-xxxx-xxxx-ee414eb0f5b1/_apis/Identities/8fe521c4-xxxx-xxxx-xxxx-6ca5f1b30c10; _links=; id=8
fe521c4-xxxx-xxxx-xxxx-6ca5f1b30c10; uniqueName=Kabir@software.com; imageUrl=https://condecosoftware.visualstudio.com/_apis/GraphProfile/MemberAvatars/aad.OGZlNLWFlZTgtNmNhNWYxYjMwY
zEw; descriptor=aad.OGZlNTIxYzQtYmQwNy03MNmNhNWYxYjMwYzEw}",
                      "id":  10,
                      "scope":  "3e93f9e6-xxxx-xxxx-xxxx-994d196e1121",
                      "name":  "PaasAgent1",
                      "isHosted":  false,
                      "poolType":  "automation",
                      "size":  0
                  }]

Теперь я хочу обновить пул агентов в определении выпуска.

Ссылка: Могу ли я массово изменить очередь агента в VSTS?

1 Ответ

0 голосов
/ 04 апреля 2019

Вам потребуется изменить объект, возвращаемый при вызове $ uri2, а затем использовать метод PUT HTTP для обновления определения выпуска в Azure DevOps.

Преобразование $ projects2 в и из JSON не требуется, объекты не нужныможно манипулировать напрямую.Удалите | ConvertTo-Json из конца Invoke-RestMethod, который устанавливает $ project2, а также строку $projects2 = $projects2 | ConvertFrom-Json.

. Чтобы изменить изменение пула агентов, вам необходимо обновить свойство queueId соответствующего развертывания.фаза в соответствующей среде.Если бы у вас была 1 среда с 1 фазой развертывания, это было бы сделано

$projects2.environments[0].deployPhases[0].deploymentInput.queueId = $id.id

Если у вас несколько сред и / или фаз развертывания, вам необходимо соответствующим образом изменить ключи массива в этих свойствах.Затем преобразуйте объект $ projects2 в JSON перед отправкой HTTP-запроса PUT:

$body = $projects2 | ConvertTo-Json -Depth 10
$uri3 = "https://vsrm.dev.azure.com/$vstsAccount/$resource/_apis/release/definitions?api-version=5.0"
Invoke-RestMethod -Method Put -Uri $uri3 -Headers @{Authorization=("Basic {0}" -f $base64authinfo)} -Body $body -ContentType application/json
...