From 4cfb7828184545a7faa440a17f3fc1f2bf2c7cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Fri, 28 Feb 2020 14:01:15 +0100 Subject: [PATCH 1/3] Added script to update agent version --- Source/Public/Update-VSTeamAgent.ps1 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Source/Public/Update-VSTeamAgent.ps1 diff --git a/Source/Public/Update-VSTeamAgent.ps1 b/Source/Public/Update-VSTeamAgent.ps1 new file mode 100644 index 000000000..05775b4b2 --- /dev/null +++ b/Source/Public/Update-VSTeamAgent.ps1 @@ -0,0 +1,22 @@ +function Update-VSTeamAgent { + param( + [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] + [int] $PoolId, + + [parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 1)] + [Alias('AgentID')] + [int[]] $Id + ) + + process { + foreach ($item in $Id) { + try { + _callAPI -Method Post -Area "distributedtask/pools/$PoolId" -Resource messages -QueryString @{agentId=$item} -Version $([VSTeamVersions]::DistributedTask) -ContentType "application/json" | Out-Null + Write-Output "Update agent $item" + } + catch { + _handleException $_ + } + } + } +} \ No newline at end of file From fcd3c282c4ff0f368bcaa66feb4f2515c8771d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Fri, 28 Feb 2020 14:34:11 +0100 Subject: [PATCH 2/3] Added docs and tests --- .docs/Update-VSTeamAgent.md | 48 ++++++++++++++++++++++++++++ .docs/synopsis/Update-VSTeamAgent.md | 1 + CHANGELOG.md | 6 ++++ unit/test/agents.Tests.ps1 | 21 ++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 .docs/Update-VSTeamAgent.md create mode 100644 .docs/synopsis/Update-VSTeamAgent.md diff --git a/.docs/Update-VSTeamAgent.md b/.docs/Update-VSTeamAgent.md new file mode 100644 index 000000000..2566dc50e --- /dev/null +++ b/.docs/Update-VSTeamAgent.md @@ -0,0 +1,48 @@ + + +# Update-VSTeamAgent + +## SYNOPSIS + + + +## SYNTAX + +## DESCRIPTION + + + +## EXAMPLES + +## PARAMETERS + +### -PoolId + +Id of the pool. + +```yaml +Type: int +Required: True +Accept pipeline input: true (ByValue) +``` + +### -Id + +Id of the agent to Update. + +```yaml +Type: int[] +Aliases: AgentID +Required: True +Accept pipeline input: true (ByPropertyName) +``` + +## INPUTS + +### System.String + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/.docs/synopsis/Update-VSTeamAgent.md b/.docs/synopsis/Update-VSTeamAgent.md new file mode 100644 index 000000000..b7db1b844 --- /dev/null +++ b/.docs/synopsis/Update-VSTeamAgent.md @@ -0,0 +1 @@ +Update an agent in a pool. \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8e95283..68e737afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 6.4.5 + +Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/273) from [Lukas Wöhrl](https://github.com/woehrl01) which included the following: + +Adds a new function Update-VSTeamAgent which allows to update the agent version + ## 6.4.4 Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/257) from [Michel Zehnder](https://github.com/MichelZ) which included the following: diff --git a/unit/test/agents.Tests.ps1 b/unit/test/agents.Tests.ps1 index bfb8fdc5a..0f7724480 100644 --- a/unit/test/agents.Tests.ps1 +++ b/unit/test/agents.Tests.ps1 @@ -130,5 +130,26 @@ InModuleScope VSTeam { { Disable-VSTeamAgent -Pool 36 -Id 950 } | Should Throw } } + + Context 'Update-VSTeamAgent by ID' { + Mock Invoke-RestMethod + + It 'should update the agent with passed in Id' { + Update-VSTeamAgent -Pool 36 -Id 950 + + Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter { + $Method -eq 'Post' -and + $Uri -eq "https://dev.azure.com/test/_apis/distributedtask/pools/36/messages?api-version=$([VSTeamVersions]::DistributedTask)&agentId=950" + } + } + } + + Context 'Update-VSTeamAgent throws' { + Mock Invoke-RestMethod { throw 'boom' } + + It 'should update the agent with passed in Id' { + { Disable-VSTeamAgent -Pool 36 -Id 950 } | Should Throw + } + } } } \ No newline at end of file From 9a4b52108f6de52b6c60e13192f86dc5ca602905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20W=C3=B6hrl?= Date: Fri, 28 Feb 2020 20:36:59 +0100 Subject: [PATCH 3/3] Improve unittests for Update-VSTeamAgent --- unit/test/agents.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/unit/test/agents.Tests.ps1 b/unit/test/agents.Tests.ps1 index 0f7724480..27858d069 100644 --- a/unit/test/agents.Tests.ps1 +++ b/unit/test/agents.Tests.ps1 @@ -139,7 +139,9 @@ InModuleScope VSTeam { Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter { $Method -eq 'Post' -and - $Uri -eq "https://dev.azure.com/test/_apis/distributedtask/pools/36/messages?api-version=$([VSTeamVersions]::DistributedTask)&agentId=950" + $Uri -like "*https://dev.azure.com/test/_apis/distributedtask/pools/36/messages*" -and + $Uri -like "*api-version=$([VSTeamVersions]::DistributedTask)*" -and + $Uri -like "*agentId=950*" } } } @@ -148,7 +150,7 @@ InModuleScope VSTeam { Mock Invoke-RestMethod { throw 'boom' } It 'should update the agent with passed in Id' { - { Disable-VSTeamAgent -Pool 36 -Id 950 } | Should Throw + { Update-VSTeamAgent -Pool 36 -Id 950 } | Should Throw } } }