diff --git a/README.md b/README.md index 92f21415f..37f4c7a97 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,14 @@ The cases of every file is very important. This module is to be used on Windows, ### 3.0.5 -Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/70) from [Geert van der Cruijsen](https://github.com/Geertvdc) which included the following: +Merged [Pull Request 70](https://github.com/DarqueWarrior/vsteam/pull/70) and [Pull Request 72](https://github.com/DarqueWarrior/vsteam/pull/72) from [Geert van der Cruijsen](https://github.com/Geertvdc) which included the following: -Added a function to remove vsts agents from a pool. by calling Remove-Agent or Remove-VSTeamAgent +- Added a function to remove vsts agents from a pool by calling Remove-Agent or Remove-VSTeamAgent +- Disable & Enable agents in pool + +Add [Pull Request 70](https://github.com/DarqueWarrior/vsteam/pull/71) from [Kai Walter](https://github.com/KaiWalter) which included the following: + +Integration tests for Build Definitions ### 3.0.4 @@ -24,7 +29,7 @@ The ProjectName dynamic parameter that enables Tab Complete of project names was ### 3.0.3 -Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/66) from [Kai Walter](https://github.com/KaiWalter) which included the following: +Merged [Pull Request 66](https://github.com/DarqueWarrior/vsteam/pull/66) from [Kai Walter](https://github.com/KaiWalter) which included the following: Updated integration tests to account for the new hosted agent pool. diff --git a/integration/test/010_builddef_1.json b/integration/test/010_builddef_1.json new file mode 100644 index 000000000..debfff8ef --- /dev/null +++ b/integration/test/010_builddef_1.json @@ -0,0 +1,96 @@ +{ + "options": [], + "variables": { + "system.debug": { + "value": "false", + "allowOverride": true + } + }, + "retentionRules": [{ + "branches": ["+refs/heads/*"], + "artifacts": [], + "artifactTypesToDelete": ["FilePath", "SymbolStore"], + "daysToKeep": 10, + "minimumToKeep": 1, + "deleteBuildRecord": true, + "deleteTestResults": true + }], + "properties": {}, + "tags": [], + "jobAuthorizationScope": 1, + "jobTimeoutInMinutes": 60, + "jobCancelTimeoutInMinutes": 5, + "process": { + "phases": [{ + "steps": [{ + "environment": {}, + "enabled": true, + "continueOnError": false, + "alwaysRun": false, + "displayName": "PowerShell Script", + "timeoutInMinutes": 0, + "condition": "succeeded()", + "task": { + "id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1", + "versionSpec": "2.*", + "definitionType": "task" + }, + "inputs": { + "targetType": "inline", + "filePath": "", + "arguments": "", + "script": "Write-Host \"Hello World\"", + "errorActionPreference": "stop", + "failOnStderr": "false", + "ignoreLASTEXITCODE": "false", + "workingDirectory": "" + } + }], + "name": "Phase 1", + "refName": "Phase_1", + "condition": "succeeded()", + "target": { + "executionOptions": { + "type": 0 + }, + "allowScriptsAuthAccessOption": false, + "type": 1 + }, + "jobAuthorizationScope": "projectCollection", + "jobCancelTimeoutInMinutes": 1 + }], + "type": 1 + }, + "repository": { + "properties": { + "cleanOptions": "0", + "labelSources": "0", + "labelSourcesFormat": "$(build.buildNumber)", + "reportBuildStatus": "true", + "gitLfsSupport": "false", + "skipSyncSource": "false", + "checkoutNestedSubmodules": "false", + "fetchDepth": "0" + }, + "id": "1c78f0c9-82a4-4444-955b-ce0def7e2399", + "type": "TfsGit", + "name": "CI", + "defaultBranch": "refs/heads/master", + "clean": "false", + "checkoutSubmodules": false + }, + "processParameters": {}, + "quality": 1, + "drafts": [], + "queue": { + "id": 231 + }, + "name": "TeamModuleIntegrationfd41f186cd1-CI", + "path": "\\", + "type": 2, + "queueStatus": 0, + "revision": 1, + "project": { + "id": "a4513ce5-464e-4a57-82ec-8bcfd4a671c7" + } +} \ No newline at end of file diff --git a/integration/test/010_builddef_2.json b/integration/test/010_builddef_2.json new file mode 100644 index 000000000..30e2b4db1 --- /dev/null +++ b/integration/test/010_builddef_2.json @@ -0,0 +1,125 @@ +{ + "options": [], + "variables": { + "system.debug": { + "value": "false", + "allowOverride": true + } + }, + "retentionRules": [{ + "branches": ["+refs/heads/*"], + "artifacts": [], + "artifactTypesToDelete": ["FilePath", "SymbolStore"], + "daysToKeep": 10, + "minimumToKeep": 1, + "deleteBuildRecord": true, + "deleteTestResults": true + }], + "properties": {}, + "tags": [], + "jobAuthorizationScope": 1, + "jobTimeoutInMinutes": 60, + "jobCancelTimeoutInMinutes": 5, + "process": { + "phases": [{ + "steps": [{ + "environment": {}, + "enabled": true, + "continueOnError": false, + "alwaysRun": false, + "displayName": "PowerShell Script", + "timeoutInMinutes": 0, + "condition": "succeeded()", + "task": { + "id": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1", + "versionSpec": "2.*", + "definitionType": "task" + }, + "inputs": { + "targetType": "inline", + "filePath": "", + "arguments": "", + "script": "Write-Host \"Hello World\"", + "errorActionPreference": "stop", + "failOnStderr": "false", + "ignoreLASTEXITCODE": "false", + "workingDirectory": "" + } + }], + "name": "Phase 1", + "refName": "Phase_1", + "condition": "succeeded()", + "target": { + "executionOptions": { + "type": 0 + }, + "allowScriptsAuthAccessOption": false, + "type": 1 + }, + "jobAuthorizationScope": "projectCollection", + "jobCancelTimeoutInMinutes": 1 + }, { + "steps": [{ + "environment": {}, + "enabled": true, + "continueOnError": false, + "alwaysRun": false, + "displayName": "Delay by 1 minutes", + "timeoutInMinutes": 0, + "condition": "succeeded()", + "task": { + "id": "28782b92-5e8e-4458-9751-a71cd1492bae", + "versionSpec": "1.*", + "definitionType": "task" + }, + "inputs": { + "delayForMinutes": "1" + } + }], + "name": "Agentless phase", + "refName": "Phase_2", + "condition": "succeeded()", + "target": { + "executionOptions": { + "type": 0 + }, + "type": 2 + }, + "jobAuthorizationScope": "projectCollection", + "jobCancelTimeoutInMinutes": 1 + }], + "type": 1 + }, + "repository": { + "properties": { + "cleanOptions": "0", + "labelSources": "0", + "labelSourcesFormat": "$(build.buildNumber)", + "reportBuildStatus": "true", + "gitLfsSupport": "false", + "skipSyncSource": "false", + "checkoutNestedSubmodules": "false", + "fetchDepth": "0" + }, + "id": "1c78f0c9-82a4-4444-955b-ce0def7e2399", + "type": "TfsGit", + "name": "CI", + "defaultBranch": "refs/heads/master", + "clean": "false", + "checkoutSubmodules": false + }, + "processParameters": {}, + "quality": 1, + "drafts": [], + "queue": { + "id": 231 + }, + "name": "TeamModuleIntegrationfd41f186cd1-CI", + "path": "\\", + "type": 2, + "queueStatus": 0, + "revision": 1, + "project": { + "id": "a4513ce5-464e-4a57-82ec-8bcfd4a671c7" + } +} \ No newline at end of file diff --git a/integration/test/010_projects.Tests.ps1 b/integration/test/010_projects.Tests.ps1 index bdd313d48..3be9e1be3 100644 --- a/integration/test/010_projects.Tests.ps1 +++ b/integration/test/010_projects.Tests.ps1 @@ -35,7 +35,7 @@ Describe 'VSTeam Integration Tests' -Tag 'integration' { # The way we search for the account is different for VSTS and TFS $search = "*$acct*" - if($api -eq 'VSTS') { + if ($api -eq 'VSTS') { $search = "*//$acct.*" } @@ -162,6 +162,66 @@ Describe 'VSTeam Integration Tests' -Tag 'integration' { } } + Context 'BuildDefinition full exercise' { + + Add-VSTeamGitRepository -ProjectName $newProjectName -Name 'CI' + $project = $repo = Get-VSTeamProject -Name $newProjectName + $repo = Get-VSTeamGitRepository -ProjectName $newProjectName -Name 'CI' + + if ($acct -like "http://*") { + $defaultQueue = Get-VSTeamQueue -ProjectName $newProjectName | Where-Object {$_.poolName -eq "Default"} + } + else { + $defaultQueue = Get-VSTeamQueue -ProjectName $newProjectName | Where-Object {$_.poolName -eq "Hosted"} + } + + $srcBuildDef = Get-Content $(Join-Path $PSScriptRoot "010_builddef_1.json") | ConvertFrom-Json + $srcBuildDef.project.id = $project.Id + $srcBuildDef.queue.id = $defaultQueue.Id + $srcBuildDef.repository.id = $repo.Id + $srcBuildDef.name = $newProjectName + "-CI1" + $tmpBuildDef1 = (New-TemporaryFile).FullName + $srcBuildDef | ConvertTo-Json -Depth 10 | Set-Content -Path $tmpBuildDef1 + + $srcBuildDef = Get-Content $(Join-Path $PSScriptRoot "010_builddef_2.json") | ConvertFrom-Json + $srcBuildDef.project.id = $project.Id + $srcBuildDef.queue.id = $defaultQueue.Id + $srcBuildDef.repository.id = $repo.Id + $srcBuildDef.name = $newProjectName + "-CI2" + $tmpBuildDef2 = (New-TemporaryFile).FullName + $srcBuildDef | ConvertTo-Json -Depth 10 | Set-Content -Path $tmpBuildDef2 + + It 'Add-VSTeamBuildDefinition should add a build definition' { + Add-VSTeamBuildDefinition -ProjectName $newProjectName -InFile $tmpBuildDef1 + $buildDef = Get-VSTeamBuildDefinition -ProjectName $newProjectName + $buildDef | Should Not Be $null + } + + It 'Add-VSTeamBuildDefinition should add another build definition' { + Add-VSTeamBuildDefinition -ProjectName $newProjectName -InFile $tmpBuildDef2 + $buildDefs = Get-VSTeamBuildDefinition -ProjectName $newProjectName + $buildDefs.Count | Should Be 2 + } + + # Only run for VSTS + if ($api -eq 'VSTS') { + It 'Get-VSTeamBuildDefinition by Id should return 1 phase for 1st build definition' { + $buildDefId = (Get-VSTeamBuildDefinition -ProjectName $newProjectName | Where-Object {$_.Name -like "*CI1"}).Id + ((Get-VSTeamBuildDefinition -ProjectName $newProjectName -Id $buildDefId).Process.Phases).Count | Should Be 1 + } + + It 'Get-VSTeamBuildDefinition by Id should return 2 phase for 2nd build definition' { + $buildDefId = (Get-VSTeamBuildDefinition -ProjectName $newProjectName | Where-Object {$_.Name -like "*CI2"}).Id + ((Get-VSTeamBuildDefinition -ProjectName $newProjectName -Id $buildDefId).Process.Phases).Count | Should Be 2 + } + } + + It 'Remove-VSTeamBuildDefinition should delete build definition' { + Get-VSTeamBuildDefinition -ProjectName $newProjectName | Remove-VSTeamBuildDefinition -ProjectName $newProjectName -Force + Get-VSTeamBuildDefinition -ProjectName $newProjectName | Should Be $null + } + } + Context 'Pool full exercise' { It 'Get-VSTeamPool Should return agent pools' { $actual = Get-VSTeamPool