From f15d119c5be76b76c892985aeaab0448ed3a3018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Tue, 25 Feb 2020 19:05:42 +0100 Subject: [PATCH 01/18] set AzD Services to use the newest api version by default --- Source/Public/Set-VSTeamAPIVersion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Public/Set-VSTeamAPIVersion.ps1 b/Source/Public/Set-VSTeamAPIVersion.ps1 index 10a3bc199..e3bf5fb92 100644 --- a/Source/Public/Set-VSTeamAPIVersion.ps1 +++ b/Source/Public/Set-VSTeamAPIVersion.ps1 @@ -112,7 +112,7 @@ function Set-VSTeamAPIVersion { [VSTeamVersions]::Version = $Target [VSTeamVersions]::Git = '5.1-preview' [VSTeamVersions]::Core = '5.0' - [VSTeamVersions]::Build = '5.0-preview' + [VSTeamVersions]::Build = '5.1-preview' [VSTeamVersions]::Release = '5.1-preview' [VSTeamVersions]::DistributedTask = '5.0-preview' [VSTeamVersions]::VariableGroups = '5.0-preview.1' From 7e28f764ebc10dc944aed037b4154849c7f40b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Tue, 25 Feb 2020 19:06:12 +0100 Subject: [PATCH 02/18] added Test-VSTeamYamlPipeline function --- Source/Public/Test-VSTeamYamlPipeline.ps1 | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Source/Public/Test-VSTeamYamlPipeline.ps1 diff --git a/Source/Public/Test-VSTeamYamlPipeline.ps1 b/Source/Public/Test-VSTeamYamlPipeline.ps1 new file mode 100644 index 000000000..b6debe10d --- /dev/null +++ b/Source/Public/Test-VSTeamYamlPipeline.ps1 @@ -0,0 +1,42 @@ +function Test-VSTeamYamlPipeline { + param( + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Int32] $PipelineId, + [Parameter(Mandatory = $false)] + [string] $FilePath + ) + DynamicParam { + _buildProjectNameDynamicParam + } + + process { + # Bind the parameter to a friendly variable + $ProjectName = $PSBoundParameters["ProjectName"] + + $body = @{ + PreviewRun = $true + } + + if ($FilePath) { + $body.YamlOverride = [string](Get-Content -raw $FilePath) + } + + try { + # Call the REST API + $resp = _callAPI -ProjectName $ProjectName -Area 'pipelines' -Resource "$PipelineId" -id "runs" ` + -Method Post -ContentType 'application/json' -Body ($body | ConvertTo-Json) ` + -Version $([VSTeamVersions]::Build) + } + catch { + if ($PSItem -match 'PipelineValidationException') { + Write-Error (($PSItem | ConvertFrom-Json).message -replace '/azure-pipelines.yml( ?: ?)? ?', '') + return + } + else { + throw + } + } + + return $resp + } +} \ No newline at end of file From d8ae10285754ca4ea454278c40ee419071148ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 26 Feb 2020 08:20:18 +0100 Subject: [PATCH 03/18] adding documentation --- .docs/Test-VSTeamYamlPipeline.md | 68 +++++++++++++++++++++++ .docs/synopsis/Test-VSTeamYamlPipeline.md | 1 + 2 files changed, 69 insertions(+) create mode 100644 .docs/Test-VSTeamYamlPipeline.md create mode 100644 .docs/synopsis/Test-VSTeamYamlPipeline.md diff --git a/.docs/Test-VSTeamYamlPipeline.md b/.docs/Test-VSTeamYamlPipeline.md new file mode 100644 index 000000000..cc20f71f1 --- /dev/null +++ b/.docs/Test-VSTeamYamlPipeline.md @@ -0,0 +1,68 @@ + + +# Test-VSTeamMembership + +## SYNOPSIS + + + +## SYNTAX + +## DESCRIPTION + + + +## EXAMPLES + +### -------------------------- EXAMPLE 1 -------------------------- + +```PowerShell +PS C:\> Test-VSTeamYamlPipeline -Project DemoProject -PipelineId 24 -FilePath './azure-pipelines.yml' + +Build Definition Build Number Status Result +---------------- ------------ ------ ------ +Demo-CI Demo-CI-45 notStarted +``` + +This example checks the YAML pipeline with ID 24 and the file './azure-pipelines.yml' for consistency on Azure DevOps to see if the changes still work. + +## PARAMETERS + + + +### -PipelineId + +Id of the YAML pipeline to be checked + +```yaml +Type: Int32 +Position: 1 +``` + +### -FilePath + +Path to the file that should be checked + +```yaml +Type: String +``` + +## INPUTS + +### System.String + +FilePath + +### System.Int32 + +PipelineId + +## OUTPUTS + +### Team.YamlPipelineResult + +## NOTES + +If you do not set the default project by called Set-VSTeamDefaultProject before calling Add-VSTeamBuild you will have to type in the names. + +## RELATED LINKS diff --git a/.docs/synopsis/Test-VSTeamYamlPipeline.md b/.docs/synopsis/Test-VSTeamYamlPipeline.md new file mode 100644 index 000000000..7119b9e00 --- /dev/null +++ b/.docs/synopsis/Test-VSTeamYamlPipeline.md @@ -0,0 +1 @@ +Tests the commited YAML pipeline files to check for inconsitencies. \ No newline at end of file From 30bac95f824142e3b227755f4652c309a3e89187 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 26 Feb 2020 08:20:31 +0100 Subject: [PATCH 04/18] adding format --- .../Team.YamlPipelineResult.TableView.ps1xml | 45 +++++++++++++++++++ Source/formats/_formats.json | 3 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Source/formats/Team.YamlPipelineResult.TableView.ps1xml diff --git a/Source/formats/Team.YamlPipelineResult.TableView.ps1xml b/Source/formats/Team.YamlPipelineResult.TableView.ps1xml new file mode 100644 index 000000000..fb56014ce --- /dev/null +++ b/Source/formats/Team.YamlPipelineResult.TableView.ps1xml @@ -0,0 +1,45 @@ + + + + + Team.YamlPipelineResult.TableView + + Team.YamlPipelineResult + + + + + + + + + + + + + + + + + + + + + name + + + id + + + url + + + state + + + + + + + + \ No newline at end of file diff --git a/Source/formats/_formats.json b/Source/formats/_formats.json index 0a26e9a2d..a2317c21d 100644 --- a/Source/formats/_formats.json +++ b/Source/formats/_formats.json @@ -97,6 +97,7 @@ "Team.WorkItemDeleted.ListView.ps1xml", "Team.JobRequest.TableView.ps1xml", "Team.GitCommitRef.TableView.ps1xml", - "Team.GitUserDate.TableView.ps1xml" + "Team.GitUserDate.TableView.ps1xml", + "Team.YamlPipelineResult.TableView.ps1xml" ] } \ No newline at end of file From 2960fd4c804f7847efc93d72428ad2f1bcf0bbfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 26 Feb 2020 08:20:48 +0100 Subject: [PATCH 05/18] adding type --- Source/Private/applyTypes.ps1 | 6 +++ Source/types/Team.YamlPipelineResult.ps1xml | 51 +++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 Source/types/Team.YamlPipelineResult.ps1xml diff --git a/Source/Private/applyTypes.ps1 b/Source/Private/applyTypes.ps1 index 98da653a4..4c028f702 100644 --- a/Source/Private/applyTypes.ps1 +++ b/Source/Private/applyTypes.ps1 @@ -194,3 +194,9 @@ function _applyTypesToVariableGroup { } $item.variables.PSObject.TypeNames.Insert(0, 'Team.Variables') } + +function _applyTypesToYamlPipelineResultType { + param($item) + + $item.PSObject.TypeNames.Insert(0, 'Team.YamlPipelineResult') +} diff --git a/Source/types/Team.YamlPipelineResult.ps1xml b/Source/types/Team.YamlPipelineResult.ps1xml new file mode 100644 index 000000000..593d4aaca --- /dev/null +++ b/Source/types/Team.YamlPipelineResult.ps1xml @@ -0,0 +1,51 @@ + + + + Team.YamlPipelineResult + + + links + $this._links + + + pipeline + $this.pipeline + + + state + $this.state + + + url + $this.url + + + finalYaml + $this.finalYaml + + + id + $this.id + + + name + $this.name + + + PSStandardMembers + + + DefaultDisplayPropertySet + + name + id + url + state + finalYaml + + + + + + + \ No newline at end of file From 22bd1de5c191e3968983223337734cbdf3d3430b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 26 Feb 2020 08:22:38 +0100 Subject: [PATCH 06/18] returning created type --- Source/Public/Test-VSTeamYamlPipeline.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Public/Test-VSTeamYamlPipeline.ps1 b/Source/Public/Test-VSTeamYamlPipeline.ps1 index b6debe10d..9294552ee 100644 --- a/Source/Public/Test-VSTeamYamlPipeline.ps1 +++ b/Source/Public/Test-VSTeamYamlPipeline.ps1 @@ -1,6 +1,6 @@ function Test-VSTeamYamlPipeline { param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] + [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)] [Int32] $PipelineId, [Parameter(Mandatory = $false)] [string] $FilePath @@ -37,6 +37,8 @@ function Test-VSTeamYamlPipeline { } } + _applyTypesToYamlPipelineResultType -item $resp + return $resp } } \ No newline at end of file From 970ed3419a3e25ce027d911101404d07f765d4ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 26 Feb 2020 23:58:57 +0100 Subject: [PATCH 07/18] added sample files for tests --- .../test/sampleFiles/azure-pipelines.test.yml | 213 ++++++++++++++++++ .../sampleFiles/pipelineDefYamlResult.json | 50 ++++ 2 files changed, 263 insertions(+) create mode 100644 unit/test/sampleFiles/azure-pipelines.test.yml create mode 100644 unit/test/sampleFiles/pipelineDefYamlResult.json diff --git a/unit/test/sampleFiles/azure-pipelines.test.yml b/unit/test/sampleFiles/azure-pipelines.test.yml new file mode 100644 index 000000000..0099540cb --- /dev/null +++ b/unit/test/sampleFiles/azure-pipelines.test.yml @@ -0,0 +1,213 @@ +name: $(Build.BuildID) + +trigger: +- master + +resources: +- repo: self + +variables: + Folder: 'dist' + TEAM_CIBUILD: 'true' + +stages: +- stage: Build + displayName: Build Stage + + jobs: + + - job: Windows_Phase + displayName: Build Windows + pool: + vmImage: 'windows-latest' + + steps: + + - task: PowerShell@2 + displayName: 'Install PSScriptAnalyzer' + inputs: + targetType: 'inline' + script: 'Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser -Verbose' + + - task: PowerShell@2 + displayName: 'Run Static Code Analysis' + inputs: + targetType: 'inline' + script: | + # Has to happen in this task for it to take effect + # Load the psd1 file so you can read the required modules and import them + $manifest = Import-PowerShellDataFile .\dist\*.psd1 + + # Import each module + $manifest.RequiredModules | ForEach-Object { Import-Module -Name $_ } + + $r = Invoke-ScriptAnalyzer -Path ./dist -Recurse | Where-Object severity -ne "Information" + $r | ForEach-Object {Write-Host "##vso[task.logissue type=$($_.Severity);sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)"} + + - task: CopyFiles@2 + displayName: 'Copy Module to Artifacts Folder' + inputs: + Contents: | + README.md + .gitignore + dist\** + TargetFolder: '$(build.artifactstagingdirectory)/VSTeam' + flattenFolders: false + condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) + + - task: PublishPipelineArtifact@1 + displayName: 'Publish Module' + inputs: + targetPath: '$(Build.ArtifactStagingDirectory)/VSTeam' + artifact: 'module' + condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) + + - task: CopyFiles@2 + displayName: 'Copy Integration Tests Artifacts Folder' + inputs: + Contents: | + dist\*.psd1 + integration\** + TargetFolder: '$(build.artifactstagingdirectory)/Tests' + condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) + + - task: PublishPipelineArtifact@1 + displayName: 'Publish Tests' + inputs: + targetPath: '$(Build.ArtifactStagingDirectory)/Tests' + artifact: 'test' + condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) + +- stage: Package + displayName: Package Management + dependsOn: Build + condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) + jobs: + - deployment: Deploy + displayName: Package Management + pool: + vmImage: 'ubuntu-16.04' + environment: 'Default' + strategy: + runOnce: + deploy: + steps: + - task: NuGetToolInstaller@0 + displayName: 'Install NuGet 5.2.0' + inputs: + versionSpec: 5.2.0 + + - task: PowerShell@2 + displayName: 'Install Module Dependencies' + inputs: + targetType: 'inline' + script: | + # Load the psd1 file so you can read the required modules and install them + $manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1 + + # Install each module + $manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser } + workingDirectory: '$(Pipeline.Workspace)/Module' + + - task: PowerShell@2 + displayName: 'Compute Version Number' + inputs: + targetType: 'inline' + script: | + # Load the psd1 file so you can read the version + $manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1 + + Write-Host "##vso[task.setvariable variable=PACKAGE_VERSION;isOutput=false]$($manifest.ModuleVersion).$(Build.BuildId)" + workingDirectory: '$(Pipeline.Workspace)/Module' + + - task: PowerShell@2 + displayName: 'Create NuSpec from PSD1' + inputs: + targetType: 'inline' + script: | + Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose + ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1 + workingDirectory: '$(Pipeline.Workspace)/Module' + + - task: NuGetCommand@2 + displayName: 'Pack Module' + inputs: + command: pack + packagesToPack: '$(Pipeline.Workspace)/Module/$(Folder)/VSTeam.nuspec' + packDestination: '$(Pipeline.Workspace)/Module/$(Folder)' + versioningScheme: byEnvVar + versionEnvVar: 'PACKAGE_VERSION' + + - task: NuGetCommand@2 + displayName: 'Push Module' + inputs: + command: push + packagesToPush: '$(Pipeline.Workspace)/Module/$(Folder)/*.nupkg' + publishVstsFeed: 'vsteam' + allowPackageConflicts: true + + +- stage: Production + displayName: PowerShell Gallery / GitHub Release + jobs: + - deployment: Deploy + displayName: PowerShell Gallery / GitHub Release + pool: + vmImage: 'windows-latest' + environment: 'PowerShell Gallery' + strategy: + runOnce: + deploy: + steps: + - task: NuGetToolInstaller@0 + displayName: 'Install NuGet 5.2.0' + inputs: + versionSpec: 5.2.0 + + - task: PowerShell@2 + displayName: 'Install Module Dependencies' + inputs: + targetType: 'inline' + script: | + # Load the psd1 file so you can read the required modules and install them + $manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1 + + # Install each module + $manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser } + workingDirectory: '$(Pipeline.Workspace)/Module' + + - task: PowerShell@2 + displayName: 'Create NuSpec from PSD1' + inputs: + targetType: 'inline' + script: | + Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose + ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1 + workingDirectory: '$(Pipeline.Workspace)/Module' + + - task: NuGetCommand@2 + displayName: 'Pack Module' + inputs: + command: pack + packagesToPack: '$(Pipeline.Workspace)/Module/$(Folder)/VSTeam.nuspec' + packDestination: '$(Pipeline.Workspace)/Module/$(Folder)' + + - task: NuGetCommand@2 + displayName: 'Push Module' + inputs: + command: push + packagesToPush: '$(Pipeline.Workspace)/Module/$(Folder)/*.nupkg' + nuGetFeedType: external + publishFeedCredentials: 'PowerShell Gallery' + + - task: GithubRelease@0 + displayName: 'Create GitHub Release' + inputs: + gitHubConnection: Darquewarrior + repositoryName: DarqueWarrior/vsteam + tagSource: manual + tag: v$(PACKAGE_VERSION) + addChangeLog: true + compareWith: 'lastFullRelease' + assets: | + $(Pipeline.Workspace)/Module/$(Folder)/*.nupkg diff --git a/unit/test/sampleFiles/pipelineDefYamlResult.json b/unit/test/sampleFiles/pipelineDefYamlResult.json new file mode 100644 index 000000000..cda758bf5 --- /dev/null +++ b/unit/test/sampleFiles/pipelineDefYamlResult.json @@ -0,0 +1,50 @@ +{ + "_links": { + "self": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_apis/pipelines/25/runs/-1" + }, + "web": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_build/results?buildId=-1" + }, + "pipeline.web": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_build/definition?definitionId=25" + }, + "pipeline": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_apis/pipelines/25?revision=1" + } + }, + "pipeline": { + "url": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_apis/pipelines/25?revision=1", + "id": 25, + "revision": 1, + "name": "preview", + "folder": "/" + }, + "state": "unknown", + "url": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_apis/pipelines/25/runs/-1", + "finalYaml": "name: $(Build.BuildID)\r\ntrigger:\r\n branches:\r\n include:\r\n - master\r\nresources:\r\n repositories:\r\n - repository: self\r\nvariables:\r\n- name: Folder\r\n value: dist\r\n- name: TEAM_CIBUILD\r\n value: true\r\nstages:\r\n- stage: Build\r\n displayName: Build Stage\r\n jobs:\r\n - job: Windows_Phase\r\n displayName: Build Windows\r\n pool:\r\n vmImage: windows-latest\r\n steps:\r\n - task: PowerShell@2\r\n displayName: Install PSScriptAnalyzer\r\n inputs:\r\n targetType: inline\r\n script: Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser -Verbose\r\n - task: PowerShell@2\r\n displayName: Run Static Code Analysis\r\n inputs:\r\n targetType: inline\r\n script: \u003e\r\n # Has to happen in this task for it to take effect\r\n\r\n # Load the psd1 file so you can read the required modules and import them\r\n\r\n + $manifest = Import-PowerShellDataFile .\\dist\\*.psd1\r\n\r\n\r\n # Import each module\r\n\r\n $manifest.RequiredModules | ForEach-Object { Import-Module -Name $_ }\r\n\r\n\r\n $r = Invoke-ScriptAnalyzer -Path ./dist -Recurse | Where-Object severity -ne \"Information\"\r\n\r\n $r | ForEach-Object {Write-Host \"##vso[task.logissue type=$($_.Severity);sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)\"}\r\n +- task: CopyFiles@2\r\n displayName: Copy Module to Artifacts Folder\r\n inputs:\r\n Contents: \u003e\r\n README.md\r\n\r\n .gitignore\r\n\r\n dist\\**\r\n TargetFolder: $(build.artifactstagingdirectory)/VSTeam\r\n flattenFolders: false\r\n condition: and(succeeded(), eq(variables[\u0027System.PullRequest.IsFork\u0027], false))\r\n - task: PublishPipelineArtifact@1\r\n displayName: Publish Module\r\n inputs:\r\n + targetPath: $(Build.ArtifactStagingDirectory)/VSTeam\r\n artifact: module\r\n condition: and(succeeded(), eq(variables[\u0027System.PullRequest.IsFork\u0027], false))\r\n - task: CopyFiles@2\r\n displayName: Copy Integration Tests Artifacts Folder\r\n inputs:\r\n Contents: \u003e\r\n dist\\*.psd1\r\n\r\n integration\\**\r\n TargetFolder: $(build.artifactstagingdirectory)/Tests\r\n condition: and(succeeded(), eq(variables[\u0027System.PullRequest.IsFork\u0027], false))\r\n - task: PublishPipelineArtifact@1\r\n displayName: Publish Tests\r\n inputs:\r\n targetPath: $(Build.ArtifactStagingDirectory)/Tests\r\n artifact: test\r\n condition: and(succeeded(), eq(variables[\u0027System.PullRequest.IsFork\u0027], false))\r\n- stage: Package\r\n displayName: Package Management\r\n dependsOn:\r\n - Build\r\n condition: and(succeeded(), eq(variables[\u0027System.PullRequest.IsFork\u0027], false))\r\n jobs:\r\n - deployment: Deploy\r\n displayName: Package Management\r\n pool:\r\n vmImage: ubuntu-16.04\r\n environment:\r\n name: Default\r\n strategy:\r\n runOnce:\r\n deploy:\r\n steps:\r\n - task: NuGetToolInstaller@0\r\n displayName: Install NuGet 5.2.0\r\n inputs:\r\n versionSpec: 5.2.0\r\n - task: PowerShell@2\r\n displayName: Install Module Dependencies\r\n + inputs:\r\n targetType: inline\r\n script: \u003e\r\n # Load the psd1 file so you can read the required modules and install them\r\n\r\n $manifest = Import-PowerShellDataFile .\\$(Folder)\\*.psd1\r\n\r\n\r\n # Install each module\r\n\r\n $manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser }\r\n workingDirectory: $(Pipeline.Workspace)/Module\r\n - task: PowerShell@2\r\n displayName: Compute Version Number\r\n inputs:\r\n targetType: inline\r\n script: \u003e\r\n # Load the psd1 file so you can +read the version\r\n\r\n $manifest = Import-PowerShellDataFile .\\$(Folder)\\*.psd1\r\n\r\n\r\n Write-Host \"##vso[task.setvariable variable=PACKAGE_VERSION;isOutput=false]$($manifest.ModuleVersion).$(Build.BuildId)\"\r\n workingDirectory: $(Pipeline.Workspace)/Module\r\n - task: PowerShell@2\r\n displayName: Create NuSpec from PSD1\r\n inputs:\r\n targetType: inline\r\n script: \u003e\r\n + Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose\r\n\r\n ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1\r\n workingDirectory: $(Pipeline.Workspace)/Module\r\n - task: NuGetCommand@2\r\n displayName: Pack Module\r\n inputs:\r\n command: pack\r\n packagesToPack: $(Pipeline.Workspace)/Module/$(Folder)/VSTeam.nuspec\r\n packDestination: $(Pipeline.Workspace)/Module/$(Folder)\r\n versioningScheme: byEnvVar\r\n versionEnvVar: PACKAGE_VERSION\r\n - task: NuGetCommand@2\r\n displayName: Push Module\r\n inputs:\r\n command: push\r\n + packagesToPush: $(Pipeline.Workspace)/Module/$(Folder)/*.nupkg\r\n publishVstsFeed: vsteam\r\n allowPackageConflicts: true\r\n- stage: Production\r\n displayName: PowerShell Gallery / GitHub Release\r\n jobs:\r\n +- deployment: Deploy\r\n displayName: PowerShell Gallery / GitHub Release\r\n pool:\r\n vmImage: windows-latest\r\n environment:\r\n name: PowerShell Gallery\r\n strategy:\r\n runOnce:\r\n deploy:\r\n steps:\r\n - task: NuGetToolInstaller@0\r\n displayName: Install NuGet 5.2.0\r\n inputs:\r\n versionSpec: 5.2.0\r\n - task: PowerShell@2\r\n displayName: Install Module Dependencies\r\n inputs:\r\n targetType: inline\r\n script: \u003e\r\n # Load the psd1 file so you can read the required modules and install them\r\n\r\n $manifest = Import-PowerShellDataFile .\\$(Folder)\\*.psd1\r\n\r\n\r\n # Install each module\r\n\r\n $manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser }\r\n workingDirectory: $(Pipeline.Workspace)/Module\r\n - task: PowerShell@2\r\n displayName: Create NuSpec from PSD1\r\n inputs:\r\n targetType: inline\r\n script: \u003e\r\n Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose\r\n\r\n ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1\r\n workingDirectory: $(Pipeline.Workspace)/Module\r\n - task: NuGetCommand@2\r\n displayName: Pack Module\r\n inputs:\r\n command: pack\r\n packagesToPack: $(Pipeline.Workspace)/Module/$(Folder)/VSTeam.nuspec\r\n packDestination: $(Pipeline.Workspace)/Module/$(Folder)\r\n - task: NuGetCommand@2\r\n displayName: Push Module\r\n inputs:\r\n command: push\r\n packagesToPush: $(Pipeline.Workspace)/Module/$(Folder)/*.nupkg\r\n nuGetFeedType: external\r\n publishFeedCredentials: PowerShell Gallery\r\n - task: GithubRelease@0\r\n displayName: Create GitHub Release\r\n inputs:\r\n gitHubConnection: Darquewarrior\r\n repositoryName: DarqueWarrior/vsteam\r\n tagSource: manual\r\n tag: v$(PACKAGE_VERSION)\r\n addChangeLog: true\r\n compareWith: lastFullRelease\r\n assets: \u003e\r\n $(Pipeline.Workspace)/Module/$(Folder)/*.nupkg\r\n\n", + "id": -1, + "name": null, + "links": { + "self": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_apis/pipelines/25/runs/-1" + }, + "web": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_build/results?buildId=-1" + }, + "pipeline.web": { + "href": "https://dev.azure.com/testorg/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_build/definition?definitionId=25" + }, + "pipeline": { + "href": "https://dev.azure.com/razorspoint/7f3c0007-705f-4e27-a2b7-0d6acfe16adf/_apis/pipelines/25?revision=1" + } + } +} \ No newline at end of file From 77d0284b57e3cc28a71b5aa43be6f66abbed2f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 26 Feb 2020 23:59:28 +0100 Subject: [PATCH 08/18] added tests and and new parameter --- Source/Public/Test-VSTeamYamlPipeline.ps1 | 15 ++-- unit/test/Test-VSTeamYamlPipeline.Tests.ps1 | 80 +++++++++++++++++++++ 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 unit/test/Test-VSTeamYamlPipeline.Tests.ps1 diff --git a/Source/Public/Test-VSTeamYamlPipeline.ps1 b/Source/Public/Test-VSTeamYamlPipeline.ps1 index 9294552ee..cbb6115d6 100644 --- a/Source/Public/Test-VSTeamYamlPipeline.ps1 +++ b/Source/Public/Test-VSTeamYamlPipeline.ps1 @@ -1,9 +1,13 @@ function Test-VSTeamYamlPipeline { + [CmdletBinding(DefaultParameterSetName = 'WithFilePath')] param( - [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)] + [Parameter(ParameterSetName = 'WithFilePath', Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)] + [Parameter(ParameterSetName = 'WithYamlOverride', Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)] [Int32] $PipelineId, - [Parameter(Mandatory = $false)] - [string] $FilePath + [Parameter(ParameterSetName = 'WithFilePath', Mandatory = $false)] + [string] $FilePath, + [Parameter(ParameterSetName = 'WithYamlOverride', Mandatory = $false)] + [string] $YamlOverride ) DynamicParam { _buildProjectNameDynamicParam @@ -14,12 +18,15 @@ function Test-VSTeamYamlPipeline { $ProjectName = $PSBoundParameters["ProjectName"] $body = @{ - PreviewRun = $true + PreviewRun = $true } if ($FilePath) { $body.YamlOverride = [string](Get-Content -raw $FilePath) } + elseif ($YamlOverride) { + $body.YamlOverride = $YamlOverride + } try { # Call the REST API diff --git a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 new file mode 100644 index 000000000..3e6ecadba --- /dev/null +++ b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 @@ -0,0 +1,80 @@ +Set-StrictMode -Version Latest + +# Loading System.Web avoids issues finding System.Web.HttpUtility +Add-Type -AssemblyName 'System.Web' + +InModuleScope VSTeam { + [VSTeamVersions]::Account = 'https://dev.azure.com/test' + + $resultsAzD = Get-Content "$PSScriptRoot\sampleFiles\pipelineDefYamlResult.json" -Raw | ConvertFrom-Json + + Describe 'Yaml Pipeline Checks AzD Services' { + # Mock the call to Get-Projects by the dynamic parameter for ProjectName + Mock Invoke-RestMethod { return @() } -ParameterFilter { + $Uri -like "*_apis/projects*" + } + + . "$PSScriptRoot\mocks\mockProjectNameDynamicParamNoPSet.ps1" + $testYamlPath = "$PSScriptRoot\sampleFiles\azure-pipelines.test.yml" + + Context 'Test-VSTeamYamlPipeline' { + Mock Invoke-RestMethod { + # If this test fails uncomment the line below to see how the mock was called. + Write-Host $args + Write-Host $([VSTeamVersions]::Build) + Write-Host $([VSTeamVersions]::Account) + + return $resultsAzD + } + + It 'With Pipeline with PipelineID and without extra YAML' { + Test-VSTeamYamlPipeline -projectName project -PipelineId 24 + + Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter { + + $Uri -like "*https://dev.azure.com/test/project/_apis/pipelines/24/runs*" -and + $Uri -like "*api-version=$([VSTeamVersions]::Build)*" -and + $Body -like '*"PreviewRun": true*' -and + $Body -notlike '*YamlOverride*' + } + } + + It 'With Pipeline with PipelineID and YAML file path' { + + Test-VSTeamYamlPipeline -projectName project -PipelineId 24 -FilePath $testYamlPath + + Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter { + + $Uri -like "*https://dev.azure.com/test/project/_apis/pipelines/24/runs*" -and + $Uri -like "*api-version=$([VSTeamVersions]::Build)*" -and + $Body -like '*"PreviewRun": true*' -and + $Body -like '*YamlOverride*' + } + } + + It 'With Pipeline with PipelineID and YAML code' { + + $yamlOverride = [string](Get-Content -raw $testYamlPath) + Test-VSTeamYamlPipeline -projectName project -PipelineId 24 -YamlOverride $yamlOverride + + Assert-MockCalled Invoke-RestMethod -Exactly -Scope It -Times 1 -ParameterFilter { + + $Uri -like "*https://dev.azure.com/test/project/_apis/pipelines/24/runs*" -and + $Uri -like "*api-version=$([VSTeamVersions]::Build)*" -and + $Body -like '*"PreviewRun": true*' -and + $Body -like '*YamlOverride*' + } + } + + + + $yamlResult = Test-VSTeamYamlPipeline -projectName project -PipelineId 24 -FilePath $testYamlPath + + It 'Should create Yaml result' { + $yamlResult | Should Not be $null + } + + } + + } +} \ No newline at end of file From 61d71b16adc61aef999e1f904191bb730dc5f645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 00:05:14 +0100 Subject: [PATCH 09/18] docs header fix --- .docs/Test-VSTeamYamlPipeline.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docs/Test-VSTeamYamlPipeline.md b/.docs/Test-VSTeamYamlPipeline.md index cc20f71f1..99ec90fc7 100644 --- a/.docs/Test-VSTeamYamlPipeline.md +++ b/.docs/Test-VSTeamYamlPipeline.md @@ -1,6 +1,6 @@ -# Test-VSTeamMembership +# Test-VSTeamYamlPipeline ## SYNOPSIS From 2e72fc725ba43aae97ceab9d17f21af39f306d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 00:15:11 +0100 Subject: [PATCH 10/18] commented debugging lines --- unit/test/Test-VSTeamYamlPipeline.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 index 3e6ecadba..0c8df046e 100644 --- a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 +++ b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 @@ -20,9 +20,9 @@ InModuleScope VSTeam { Context 'Test-VSTeamYamlPipeline' { Mock Invoke-RestMethod { # If this test fails uncomment the line below to see how the mock was called. - Write-Host $args - Write-Host $([VSTeamVersions]::Build) - Write-Host $([VSTeamVersions]::Account) + #Write-Host $args + #Write-Host $([VSTeamVersions]::Build) + #Write-Host $([VSTeamVersions]::Account) return $resultsAzD } From dd2b148b7ce636d904c2b9e36b09bc0ac998409d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 09:42:48 +0100 Subject: [PATCH 11/18] Update Test-VSTeamYamlPipeline.ps1 --- Source/Public/Test-VSTeamYamlPipeline.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Public/Test-VSTeamYamlPipeline.ps1 b/Source/Public/Test-VSTeamYamlPipeline.ps1 index cbb6115d6..eaf6bc585 100644 --- a/Source/Public/Test-VSTeamYamlPipeline.ps1 +++ b/Source/Public/Test-VSTeamYamlPipeline.ps1 @@ -31,7 +31,7 @@ function Test-VSTeamYamlPipeline { try { # Call the REST API $resp = _callAPI -ProjectName $ProjectName -Area 'pipelines' -Resource "$PipelineId" -id "runs" ` - -Method Post -ContentType 'application/json' -Body ($body | ConvertTo-Json) ` + -Method Post -ContentType 'application/json; charset=utf-8' -Body ($body | ConvertTo-Json) ` -Version $([VSTeamVersions]::Build) } catch { @@ -48,4 +48,4 @@ function Test-VSTeamYamlPipeline { return $resp } -} \ No newline at end of file +} From 5ad610b25f3255fbb70ab70cf2f641e54a828850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 10:00:23 +0100 Subject: [PATCH 12/18] Simplified yaml test file --- .../test/sampleFiles/azure-pipelines.test.yml | 189 +----------------- 1 file changed, 4 insertions(+), 185 deletions(-) diff --git a/unit/test/sampleFiles/azure-pipelines.test.yml b/unit/test/sampleFiles/azure-pipelines.test.yml index 0099540cb..1c09aebad 100644 --- a/unit/test/sampleFiles/azure-pipelines.test.yml +++ b/unit/test/sampleFiles/azure-pipelines.test.yml @@ -1,4 +1,4 @@ -name: $(Build.BuildID) +name: Test-Yaml-Pipeline trigger: - master @@ -6,10 +6,6 @@ trigger: resources: - repo: self -variables: - Folder: 'dist' - TEAM_CIBUILD: 'true' - stages: - stage: Build displayName: Build Stage @@ -22,192 +18,15 @@ stages: vmImage: 'windows-latest' steps: - - - task: PowerShell@2 - displayName: 'Install PSScriptAnalyzer' - inputs: - targetType: 'inline' - script: 'Install-Module -Name PSScriptAnalyzer -Repository PSGallery -Force -Scope CurrentUser -Verbose' - - - task: PowerShell@2 - displayName: 'Run Static Code Analysis' - inputs: - targetType: 'inline' - script: | - # Has to happen in this task for it to take effect - # Load the psd1 file so you can read the required modules and import them - $manifest = Import-PowerShellDataFile .\dist\*.psd1 - - # Import each module - $manifest.RequiredModules | ForEach-Object { Import-Module -Name $_ } - - $r = Invoke-ScriptAnalyzer -Path ./dist -Recurse | Where-Object severity -ne "Information" - $r | ForEach-Object {Write-Host "##vso[task.logissue type=$($_.Severity);sourcepath=$($_.ScriptPath);linenumber=$($_.Line);columnnumber=$($_.Column);]$($_.Message)"} - - task: CopyFiles@2 displayName: 'Copy Module to Artifacts Folder' inputs: - Contents: | - README.md - .gitignore - dist\** - TargetFolder: '$(build.artifactstagingdirectory)/VSTeam' + Contents: '**' + TargetFolder: '$(build.artifactstagingdirectory)' flattenFolders: false - condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) - task: PublishPipelineArtifact@1 displayName: 'Publish Module' inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/VSTeam' + targetPath: '$(Build.ArtifactStagingDirectory)' artifact: 'module' - condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) - - - task: CopyFiles@2 - displayName: 'Copy Integration Tests Artifacts Folder' - inputs: - Contents: | - dist\*.psd1 - integration\** - TargetFolder: '$(build.artifactstagingdirectory)/Tests' - condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) - - - task: PublishPipelineArtifact@1 - displayName: 'Publish Tests' - inputs: - targetPath: '$(Build.ArtifactStagingDirectory)/Tests' - artifact: 'test' - condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) - -- stage: Package - displayName: Package Management - dependsOn: Build - condition: and(succeeded(), eq(variables['System.PullRequest.IsFork'], false)) - jobs: - - deployment: Deploy - displayName: Package Management - pool: - vmImage: 'ubuntu-16.04' - environment: 'Default' - strategy: - runOnce: - deploy: - steps: - - task: NuGetToolInstaller@0 - displayName: 'Install NuGet 5.2.0' - inputs: - versionSpec: 5.2.0 - - - task: PowerShell@2 - displayName: 'Install Module Dependencies' - inputs: - targetType: 'inline' - script: | - # Load the psd1 file so you can read the required modules and install them - $manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1 - - # Install each module - $manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser } - workingDirectory: '$(Pipeline.Workspace)/Module' - - - task: PowerShell@2 - displayName: 'Compute Version Number' - inputs: - targetType: 'inline' - script: | - # Load the psd1 file so you can read the version - $manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1 - - Write-Host "##vso[task.setvariable variable=PACKAGE_VERSION;isOutput=false]$($manifest.ModuleVersion).$(Build.BuildId)" - workingDirectory: '$(Pipeline.Workspace)/Module' - - - task: PowerShell@2 - displayName: 'Create NuSpec from PSD1' - inputs: - targetType: 'inline' - script: | - Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose - ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1 - workingDirectory: '$(Pipeline.Workspace)/Module' - - - task: NuGetCommand@2 - displayName: 'Pack Module' - inputs: - command: pack - packagesToPack: '$(Pipeline.Workspace)/Module/$(Folder)/VSTeam.nuspec' - packDestination: '$(Pipeline.Workspace)/Module/$(Folder)' - versioningScheme: byEnvVar - versionEnvVar: 'PACKAGE_VERSION' - - - task: NuGetCommand@2 - displayName: 'Push Module' - inputs: - command: push - packagesToPush: '$(Pipeline.Workspace)/Module/$(Folder)/*.nupkg' - publishVstsFeed: 'vsteam' - allowPackageConflicts: true - - -- stage: Production - displayName: PowerShell Gallery / GitHub Release - jobs: - - deployment: Deploy - displayName: PowerShell Gallery / GitHub Release - pool: - vmImage: 'windows-latest' - environment: 'PowerShell Gallery' - strategy: - runOnce: - deploy: - steps: - - task: NuGetToolInstaller@0 - displayName: 'Install NuGet 5.2.0' - inputs: - versionSpec: 5.2.0 - - - task: PowerShell@2 - displayName: 'Install Module Dependencies' - inputs: - targetType: 'inline' - script: | - # Load the psd1 file so you can read the required modules and install them - $manifest = Import-PowerShellDataFile .\$(Folder)\*.psd1 - - # Install each module - $manifest.RequiredModules | ForEach-Object { Install-Module -Name $_ -Repository PSGallery -F -Scope CurrentUser } - workingDirectory: '$(Pipeline.Workspace)/Module' - - - task: PowerShell@2 - displayName: 'Create NuSpec from PSD1' - inputs: - targetType: 'inline' - script: | - Install-Module -Name Trackyon.Nuget -Scope CurrentUser -Force -Verbose - ConvertTo-NuSpec -Path ./$(Folder)/VSTeam.psd1 - workingDirectory: '$(Pipeline.Workspace)/Module' - - - task: NuGetCommand@2 - displayName: 'Pack Module' - inputs: - command: pack - packagesToPack: '$(Pipeline.Workspace)/Module/$(Folder)/VSTeam.nuspec' - packDestination: '$(Pipeline.Workspace)/Module/$(Folder)' - - - task: NuGetCommand@2 - displayName: 'Push Module' - inputs: - command: push - packagesToPush: '$(Pipeline.Workspace)/Module/$(Folder)/*.nupkg' - nuGetFeedType: external - publishFeedCredentials: 'PowerShell Gallery' - - - task: GithubRelease@0 - displayName: 'Create GitHub Release' - inputs: - gitHubConnection: Darquewarrior - repositoryName: DarqueWarrior/vsteam - tagSource: manual - tag: v$(PACKAGE_VERSION) - addChangeLog: true - compareWith: 'lastFullRelease' - assets: | - $(Pipeline.Workspace)/Module/$(Folder)/*.nupkg From 736884e4968e3da11cff9d42a4f752248721e43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 12:05:57 +0100 Subject: [PATCH 13/18] Update Test-VSTeamYamlPipeline.Tests.ps1 --- unit/test/Test-VSTeamYamlPipeline.Tests.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 index 0c8df046e..ec0b7fc1e 100644 --- a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 +++ b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 @@ -20,9 +20,9 @@ InModuleScope VSTeam { Context 'Test-VSTeamYamlPipeline' { Mock Invoke-RestMethod { # If this test fails uncomment the line below to see how the mock was called. - #Write-Host $args - #Write-Host $([VSTeamVersions]::Build) - #Write-Host $([VSTeamVersions]::Account) + Write-Host $args + Write-Host $([VSTeamVersions]::Build) + Write-Host $([VSTeamVersions]::Account) return $resultsAzD } @@ -77,4 +77,4 @@ InModuleScope VSTeam { } } -} \ No newline at end of file +} From 21a21657c69a980bdcf06e0173aa3b9eb45a0955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 13:20:17 +0100 Subject: [PATCH 14/18] Update Test-VSTeamYamlPipeline.Tests.ps1 --- unit/test/Test-VSTeamYamlPipeline.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 index ec0b7fc1e..d8be796de 100644 --- a/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 +++ b/unit/test/Test-VSTeamYamlPipeline.Tests.ps1 @@ -34,7 +34,7 @@ InModuleScope VSTeam { $Uri -like "*https://dev.azure.com/test/project/_apis/pipelines/24/runs*" -and $Uri -like "*api-version=$([VSTeamVersions]::Build)*" -and - $Body -like '*"PreviewRun": true*' -and + $Body -like '*"PreviewRun":*true*' -and $Body -notlike '*YamlOverride*' } } @@ -47,7 +47,7 @@ InModuleScope VSTeam { $Uri -like "*https://dev.azure.com/test/project/_apis/pipelines/24/runs*" -and $Uri -like "*api-version=$([VSTeamVersions]::Build)*" -and - $Body -like '*"PreviewRun": true*' -and + $Body -like '*"PreviewRun":*true*' -and $Body -like '*YamlOverride*' } } @@ -61,7 +61,7 @@ InModuleScope VSTeam { $Uri -like "*https://dev.azure.com/test/project/_apis/pipelines/24/runs*" -and $Uri -like "*api-version=$([VSTeamVersions]::Build)*" -and - $Body -like '*"PreviewRun": true*' -and + $Body -like '*"PreviewRun":*true*' -and $Body -like '*YamlOverride*' } } From e519b547c3ea8bcb28c30446a9181068f3d8b9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 14:41:38 +0100 Subject: [PATCH 15/18] added documentation --- .docs/Test-VSTeamYamlPipeline.md | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/.docs/Test-VSTeamYamlPipeline.md b/.docs/Test-VSTeamYamlPipeline.md index 99ec90fc7..ceb9d0589 100644 --- a/.docs/Test-VSTeamYamlPipeline.md +++ b/.docs/Test-VSTeamYamlPipeline.md @@ -19,13 +19,31 @@ ```PowerShell PS C:\> Test-VSTeamYamlPipeline -Project DemoProject -PipelineId 24 -FilePath './azure-pipelines.yml' -Build Definition Build Number Status Result ----------------- ------------ ------ ------ -Demo-CI Demo-CI-45 notStarted +Name Id url state +---- -- --- ----- + -1 https://dev.azure.com/devsdb/3428bdd7-9fed-4c30-a6c9-fcb52f084ab9/_apis/pipelines/24/runs/-1 unknown ``` This example checks the YAML pipeline with ID 24 and the file './azure-pipelines.yml' for consistency on Azure DevOps to see if the changes still work. +### -------------------------- EXAMPLE 2 -------------------------- + +```PowerShell +PS C:\> $yamlOverride = [string](Get-Content -raw $FilePath) +PS C:\> Test-VSTeamYamlPipeline -Project DemoProject -PipelineId 24 -YamlOverride $yamlOverride +``` + +This example checks the YAML pipeline with ID 24 and the content of a yaml file in the variable $yamlOverride for consistency on Azure DevOps to see if the changes still work. + +### -------------------------- EXAMPLE 3 -------------------------- + +```PowerShell +PS C:\> $yamlOverride = [string](Get-Content -raw $FilePath) +PS C:\> Test-VSTeamYamlPipeline -Project DemoProject -PipelineId 24 +``` + +This example checks the YAML pipeline with ID 24 for consistency on Azure DevOps to see if the existing YAML of the pipeline works. + ## PARAMETERS @@ -66,3 +84,5 @@ PipelineId If you do not set the default project by called Set-VSTeamDefaultProject before calling Add-VSTeamBuild you will have to type in the names. ## RELATED LINKS + +[Get-VSTeamBuildDefinition](Get-VSTeamBuildDefinition.md) From 301d1a9fcec6e749812338b067ca1862b594ce58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Thu, 27 Feb 2020 14:51:14 +0100 Subject: [PATCH 16/18] added PR to changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8e95283..1f83e20b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 6.4.5 + +Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/272) from [Sebastian Schütze](https://github.com/SebastianSchuetze) which included the following: + +- Add Test-VSTeamYamlPipeline to preview check changes for YAML pipelines. [See release spront 165](https://docs.microsoft.com/en-us/azure/devops/release-notes/2020/sprint-165-update#azure-pipelines-1). + ## 6.4.4 Merged [Pull Request](https://github.com/DarqueWarrior/vsteam/pull/257) from [Michel Zehnder](https://github.com/MichelZ) which included the following: From 1c2e7cb1684cbb40b7e554f6b6a0d18d7bf24383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Fri, 28 Feb 2020 19:25:38 +0100 Subject: [PATCH 17/18] Update Test-VSTeamYamlPipeline.md --- .docs/Test-VSTeamYamlPipeline.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.docs/Test-VSTeamYamlPipeline.md b/.docs/Test-VSTeamYamlPipeline.md index ceb9d0589..4edec8c4c 100644 --- a/.docs/Test-VSTeamYamlPipeline.md +++ b/.docs/Test-VSTeamYamlPipeline.md @@ -83,6 +83,9 @@ PipelineId If you do not set the default project by called Set-VSTeamDefaultProject before calling Add-VSTeamBuild you will have to type in the names. +Currently the API that is used by this cmdlet is only supporting YAML pipelines without template references. This will be supported soon. see the issue in GitHub: https://github.com/microsoft/azure-pipelines-yaml/issues/34#issuecomment-591092498 + ## RELATED LINKS [Get-VSTeamBuildDefinition](Get-VSTeamBuildDefinition.md) + From 12979830760a5d6048af2a6928d20265da293f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Sch=C3=BCtze?= Date: Wed, 4 Mar 2020 22:43:40 +0100 Subject: [PATCH 18/18] Set theme jekyll-theme-slate --- docs/_config.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/_config.yml diff --git a/docs/_config.yml b/docs/_config.yml new file mode 100644 index 000000000..c74188174 --- /dev/null +++ b/docs/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-slate \ No newline at end of file