Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Update-VSTeamAgent to update agent version #273

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .docs/Update-VSTeamAgent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!-- #include "./common/header.md" -->

# Update-VSTeamAgent

## SYNOPSIS

<!-- #include "./synopsis/Update-VSTeamAgent.md" -->

## SYNTAX

## DESCRIPTION

<!-- #include "./synopsis/Update-VSTeamAgent.md" -->

## 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
1 change: 1 addition & 0 deletions .docs/synopsis/Update-VSTeamAgent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update an agent in a pool.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
22 changes: 22 additions & 0 deletions Source/Public/Update-VSTeamAgent.ps1
Original file line number Diff line number Diff line change
@@ -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 $_
}
}
}
}
23 changes: 23 additions & 0 deletions unit/test/agents.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,28 @@ 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 -like "*https://dev.azure.com/test/_apis/distributedtask/pools/36/messages*" -and
$Uri -like "*api-version=$([VSTeamVersions]::DistributedTask)*" -and
$Uri -like "*agentId=950*"
}
}
}

Context 'Update-VSTeamAgent throws' {
Mock Invoke-RestMethod { throw 'boom' }

It 'should update the agent with passed in Id' {
{ Update-VSTeamAgent -Pool 36 -Id 950 } | Should Throw
}
}
}
}