Skip to content

Commit e75ccfe

Browse files
Billing Cmdlets Optimized (#389)
* added billing cmdlet * added getting all orgs and user profile cmdlet * added tests for vsteambillingtoken * added documentation for cmdlets * added unit tests corrected minor bugs * making included parameters help to working on linux * corrected syntax * fixed unit test * Apply suggestions from code review Changed some minor docs mistakes, style and typos * fixed url in test * fixing docs file * fixed unit tests and compressed json output * added version 7.2.0 to changelog * - renamed files to only cover pipeline billing - fixed bugs - removed Switch for bearer token in _callAPI again * I changed Get-VSTeamAccounts to not use URL. It now uses the parts to build the path. * Formatting and typos corrected. * - added new cmdlet for getting account billing - simplified pipeline billing - added a parameter to be able to call urls without account - added unit tests and sample data * updated documentation * updated documentation * updated changelog * falsy merged duplicate line * fixing unit tests and cmdlet for biling jobs * Synopsis & 1st line of description were the same * Updated Set-VSTeamPipelineBilling docs * Formatting changes * Added a billing version * Removed hardcoded version for billing calls * Throws when billing is not supported * Updating module version * Windows build keeps failing * Fixed spelling error. * Forced dotnet restore. * trying to force restore * This might fix the build on windows! Co-authored-by: Donovan Brown <dbrown@microsoft.com>
1 parent a5d2ebe commit e75ccfe

23 files changed

+1426
-1172
lines changed

.build/unitTests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ steps:
1010
pwsh: true
1111
targetType: 'inline'
1212
${{ if eq(parameters.buildHelp, 'false') }}:
13-
script: '.\Build-Module.ps1 -installDep -configuration Release'
13+
script: '.\Build-Module.ps1 -installDep -configuration Release -ci'
1414
${{ if eq(parameters.buildHelp, 'true') }}:
15-
script: '.\Build-Module.ps1 -installDep -buildHelp -configuration Release'
15+
script: '.\Build-Module.ps1 -installDep -buildHelp -configuration Release -ci'
1616

1717
- ${{ if eq(parameters.os, 'Windows') }}:
1818
- task: DotNetCoreCLI@2
@@ -51,7 +51,7 @@ steps:
5151
$pesterArgs.Output.Verbosity = "Normal"
5252
$pesterArgs.TestResult.Enabled = $true
5353
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
54-
54+
5555
Invoke-Pester -Configuration $pesterArgs
5656
workingDirectory: '$(System.DefaultWorkingDirectory)'
5757

@@ -72,7 +72,7 @@ steps:
7272
$pesterArgs.Output.Verbosity = "Normal"
7373
$pesterArgs.TestResult.Enabled = $true
7474
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
75-
75+
7676
Invoke-Pester -Configuration $pesterArgs
7777
workingDirectory: '$(System.DefaultWorkingDirectory)'
7878
condition: and(succeededOrFailed(), eq(variables['System.PullRequest.IsFork'], true))
@@ -97,7 +97,7 @@ steps:
9797
$pesterArgs.CodeCoverage.OutputFormat = 'JaCoCo'
9898
$pesterArgs.CodeCoverage.OutputPath = "coverage.xml"
9999
$pesterArgs.CodeCoverage.Path = ".\dist\*.ps*1"
100-
100+
101101
Invoke-Pester -Configuration $pesterArgs
102102
workingDirectory: '$(System.DefaultWorkingDirectory)'
103103
condition: and(succeededOrFailed(), eq(variables['System.PullRequest.IsFork'], false))

.docs/Get-VSTeamAccountBilling.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!-- #include "./common/header.md" -->
2+
3+
# Get-VSTeamAccountBilling
4+
5+
## SYNOPSIS
6+
7+
<!-- #include "./synopsis/Get-VSTeamAccountBilling.md" -->
8+
9+
## SYNTAX
10+
11+
## DESCRIPTION
12+
13+
<!-- #include "./synopsis/Get-VSTeamAccountBilling.md" --> This includes what subscription the organization is connected. It also shows when the organization is not connected to a subscription.
14+
15+
## EXAMPLES
16+
17+
### Example 1: Set Microsoft hosted pipeline jobs
18+
19+
```powershell
20+
Get-VSTeamAccountBilling
21+
```
22+
23+
Gets the current organization billing setup.
24+
25+
## PARAMETERS
26+
27+
## INPUTS
28+
29+
## OUTPUTS
30+
31+
## NOTES
32+
33+
Beware that these operations are potentially producing costs. This is why you need to confirm or force the command.
34+
35+
<!-- #include "./common/prerequisites.md" -->
36+
37+
## RELATED LINKS
38+
39+
<!-- #include "./common/related.md" -->
40+
41+
[Get-VSTeamUserProfile](Get-VSTeamUserProfile.md)
42+
43+
[Get-VSTeamUserProfile](Get-VSTeamAccounts.md)
44+
45+
[Set-VSTeamPipelineBilling](Set-VSTeamPipelineBilling.md)

.docs/Set-VSTeamPipelineBilling.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
## DESCRIPTION
1212

13-
<!-- #include "./synopsis/Set-VSTeamPipelineBilling.md" --> This cmdlet covers what can be bought on the billing tab on organization level. At least owner or project collection administrator permissions are needed to trigger billing actions.
13+
<!-- #include "./synopsis/Set-VSTeamPipelineBilling.md" --> A minimum of owner or project collection administrator permissions are required to trigger billing actions.
1414

1515
## EXAMPLES
1616

@@ -19,25 +19,33 @@
1919
```powershell
2020
$myProfile = Get-VSTeamUserProfile -MyProfile
2121
$orgs = Get-VSTeamAccounts -MemberId $myProfile.id
22-
Set-VSTeamPipelineBilling -Type HostedPipeline -Quantity 1 -OrganizationId $orgs[0].accountId -SubscriptionId ebd42dd8-e50e-4608-aa5d-cf0c28e9aeef
22+
Set-VSTeamPipelineBilling -Type HostedPipeline -Quantity 1 -OrganizationId $orgs[0].accountId
2323
```
2424

25-
Sets the concurrent jobs on organization `$orgs[0].accountId` and subscription `ebd42dd8-e50e-4608-aa5d-cf0c28e9aeef` for hosted pipelines to 1. This means depending on what was configured before either the number has been reduced or new concurrent jobs have been bought.
26-
The cmdlet needs the organization id and the connected subscription for the organization. To get the id you can use `Get-VSTeamAccounts` and `Get-VSTeamUserProfile` to get the required data.
25+
Sets the concurrent jobs on organization `$orgs[0].accountId` for hosted pipelines to 1. Depending on the original value either the number has been reduced or new concurrent jobs have been purchased.
26+
The organization id and the connected subscription for the organization are required. To get the id you can use `Get-VSTeamAccounts` and `Get-VSTeamUserProfile`.
2727

2828
### Example 2: Set private hosted pipeline jobs
2929

3030
```powershell
31-
Set-VSTeamPipelineBilling -Type PrivatePipeline -Quantity 1 -OrganizationId 9de24e7c-2e01-496c-bde5-71f92195ae2c -SubscriptionId ebd42dd8-e50e-4608-aa5d-cf0c28e9aeef
31+
Set-VSTeamPipelineBilling -Type PrivatePipeline -Quantity 1 -OrganizationId 9de24e7c-2e01-496c-bde5-71f92195ae2c
3232
```
3333

34-
Sets the concurrent jobs for private agents on organization `9de24e7c-2e01-496c-bde5-71f92195ae2c` and subscription `ebd42dd8-e50e-4608-aa5d-cf0c28e9aeef` for hosted pipelines to 1. This means depending on what was configured before either the number has ben reduced of new concurrent jobs have been bought.
34+
Sets the concurrent jobs for private agents on organization `9de24e7c-2e01-496c-bde5-71f92195ae2c` for hosted pipelines to 1. Depending on the original value either the number has been reduced or new concurrent jobs have been purchased.
35+
36+
### Example 3: Set private hosted pipeline jobs with current organization
37+
38+
```powershell
39+
Set-VSTeamPipelineBilling -Type PrivatePipeline -Quantity 1
40+
```
41+
42+
Sets the concurrent jobs for private agents on the current set organization for hosted pipelines to 1. Depending on the original value either the number has been reduced or new concurrent jobs have been purchased.
3543

3644
## PARAMETERS
3745

3846
### -Type
3947

40-
The type of billing that is supposed to be set.
48+
The type of billing to be set.
4149

4250
```yaml
4351
Type: string
@@ -47,16 +55,7 @@ Required: true
4755
4856
### -OrganizationId
4957
50-
The organization where the billing should be set.
51-
52-
```yaml
53-
Type: string
54-
Required: true
55-
```
56-
57-
### -SubscriptionId
58-
59-
The subscription id which the organization is using.
58+
The organization to be billed.
6059
6160
```yaml
6261
Type: string
@@ -89,3 +88,5 @@ Beware that these operations are potentially producing costs. This is why you ne
8988
[Get-VSTeamUserProfile](Get-VSTeamUserProfile.md)
9089
9190
[Get-VSTeamUserProfile](Get-VSTeamAccounts.md)
91+
92+
[Get-VSTeamAccountBilling](Get-VSTeamAccountBilling.md)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Gets the current account billing setup.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Sets billing operations on the organization level.
1+
Purchases private and Microsoft hosted concurrent jobs for pipelines.

Build-Module.ps1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ param(
5353
[string]$configuration = "LibOnly",
5454

5555
[ValidateSet('Diagnostic', 'Detailed', 'Normal', 'Minimal', 'None', 'ErrorsOnly')]
56-
[string]$testOutputLevel = "ErrorsOnly"
56+
[string]$testOutputLevel = "ErrorsOnly",
57+
58+
[switch]$ci
5759
)
5860

5961
function Import-Pester {
@@ -154,14 +156,16 @@ if (-not $skipLibBuild.IsPresent) {
154156
New-Item -Path $output\bin -ItemType Directory | Out-Null
155157
}
156158

157-
$buildOutput = dotnet build --nologo --verbosity quiet --configuration $configuration | Out-String
158-
159-
Copy-Item -Destination "$output\bin\vsteam-lib.dll" -Path ".\Source\Classes\bin\$configuration\netstandard2.0\vsteam-lib.dll" -Force
160-
Copy-Item -Destination "$output\bin\Trackyon.System.Management.Automation.Abstractions.dll" -Path ".\Source\Classes\bin\$configuration\netstandard2.0\Trackyon.System.Management.Automation.Abstractions.dll" -Force
159+
# Once build machines were updated to .NET 5.0 builds started failing.
160+
$buildOutput = dotnet restore --no-cache --ignore-failed-sources --force --force-evaluate | Out-String
161+
$buildOutput += dotnet build --nologo --configuration $configuration | Out-String
161162

162-
if (-not ($buildOutput | Select-String -Pattern 'succeeded')) {
163+
if (-not ($buildOutput | Select-String -Pattern 'succeeded') -or $ci.IsPresent) {
163164
Write-Output $buildOutput
164165
}
166+
167+
Copy-Item -Destination "$output\bin\vsteam-lib.dll" -Path ".\Source\Classes\bin\$configuration\netstandard2.0\vsteam-lib.dll" -Force
168+
Copy-Item -Destination "$output\bin\Trackyon.System.Management.Automation.Abstractions.dll" -Path ".\Source\Classes\bin\$configuration\netstandard2.0\Trackyon.System.Management.Automation.Abstractions.dll" -Force
165169
}
166170

167171
Write-Output "Publishing: Complete to $output"

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
## 7.2.0
44

5-
Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/371) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:
5+
Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/371) and (https://github.com/DarqueWarrior/vsteam/pull/389) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following:
66

77
- Added Set-VSTeamPipelineBilling to buy or release Microsoft-hosted and self-hosted agents
88
- Added Get-VSTeamAccounts to get the organizations where the user has access. Where the given user is either a member or an owner
99
- Added Get-VSTeamUserProfile that gets the users profile of an account.
10+
- Added Get-VSTeamBillingAccount to get information whether the account is connected to a subscription or not.
1011
- fixed filenames of files to work on linux (casing)
12+
- added the possibility to call _callApi with a custom bearer token
13+
- added the possibility to call _callApi without the account name in the url
1114

1215
## 7.1.4
1316

Source/Classes/Versions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public enum APIs
77
Build, Release, Core, Git, DistributedTask, DistributedTaskReleased,
88
VariableGroups, Tfvc, Packaging, MemberEntitlementManagement,
99
ExtensionsManagement, ServiceEndpoints, Graph, TaskGroups, Policy,
10-
Processes, Version, HierarchyQuery, Pipelines
10+
Processes, Version, HierarchyQuery, Pipelines, Billing
1111
}
1212

1313
public static class Versions
@@ -16,6 +16,9 @@ public static void SetApiVersion(APIs service, string version)
1616
{
1717
switch (service)
1818
{
19+
case APIs.Billing:
20+
Billing = version;
21+
break;
1922
case APIs.HierarchyQuery:
2023
HierarchyQuery = version;
2124
break;
@@ -77,6 +80,8 @@ public static string GetApiVersion(APIs service)
7780
{
7881
switch (service)
7982
{
83+
case APIs.Billing:
84+
return Billing;
8085
case APIs.HierarchyQuery:
8186
return HierarchyQuery;
8287
case APIs.Build:
@@ -135,6 +140,7 @@ public static string GetApiVersion(APIs service)
135140
public static string Core { get; set; } = "3.0";
136141
public static string Build { get; set; } = "3.0";
137142
public static string HierarchyQuery { get; set; } = "";
143+
public static string Billing { get; set; } = "";
138144
public static string Release { get; set; } = "3.0-preview";
139145
public static string DistributedTask { get; set; } = "3.0-preview";
140146
public static string DistributedTaskReleased { get; set; } = "";

0 commit comments

Comments
 (0)