Skip to content

Commit

Permalink
Split pipeline to make use of templates (#2) +semver:skip
Browse files Browse the repository at this point in the history
  • Loading branch information
RobFaie authored Jul 31, 2020
1 parent 485bc88 commit f4fb748
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 166 deletions.
179 changes: 13 additions & 166 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

variables:
- name: moduleName
value: PwshTenable

trigger:
- master

Expand All @@ -14,170 +18,13 @@ stages:
- checkout: self
clean: true
persistCredentials: true
- script: dotnet tool install --global GitVersion.Tool --version 5.3.3
displayName: Install Gitversion
- pwsh: |
$raw = dotnet-gitversion
Write-Host $raw
$version = $raw | ConvertFrom-Json | ForEach-Object MajorMinorPatch
Write-Host "##vso[build.updatebuildnumber]$version"
displayName: Set Build Number
- pwsh: |
$rawManifest = Get-Content -Path "PwshTenable.psd1" -raw
$updatedManifest = $rawManifest -replace "ModuleVersion\s*=\s*['`"][0-9.]+['`"]", "ModuleVersion = '$(Build.BuildNumber)'"
$updatedManifest | Out-File -Path "PwshTenable.psd1" -NoNewline
displayName: Update Module Manifest Version Number
- task: CopyFiles@2
inputs:
contents: |
**/*
!**/.*/**/*
!**/.*
!azure-pipelines.yml
!gitversion.yml
targetFolder: $(Build.ArtifactStagingDirectory)/PwshTenable
- publish: '$(Build.ArtifactStagingDirectory)/PwshTenable'
artifact: 'files'
displayName: 'Publish Artifact files'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)/PwshTenable
archiveFile: '$(Build.ArtifactStagingDirectory)/PwshTenable_$(Build.BuildNumber).zip'
displayName: 'Archive zip'
- publish: '$(Build.ArtifactStagingDirectory)/PwshTenable_$(Build.BuildNumber).zip'
artifact: 'zip'
displayName: 'Publish Artifact zip'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)/PwshTenable
archiveType: tar
archiveFile: '$(Build.ArtifactStagingDirectory)/PwshTenable_$(Build.BuildNumber).tar.gz'
displayName: 'Archive tar'
- publish: '$(Build.ArtifactStagingDirectory)/PwshTenable_$(Build.BuildNumber).tar.gz'
artifact: 'tar'
displayName: 'Publish Artifact tar'

- stage: Test
jobs:

- job: Mac_10_14
pool:
vmImage: 'macOS-10.14'
steps:
- checkout: none
- download: current
artifact: files
- pwsh: $PSVersionTable | Out-String
displayName: PSVersionTable
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/'
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -MinimumVersion 5.0 -Repository PSGallery -Confirm:$false
Import-Module -Name './Pester/'
Get-Module Pester | Select Version, Name
Set-Location -Path '$(Pipeline.Workspace)'
Invoke-Pester -CI
displayName: Pester
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'testResults.xml'
searchFolder: $(Pipeline.Workspace)
mergeTestResults: true
buildPlatform: Mac 10.14

- job: Ubuntu_18_04
pool:
vmImage: 'ubuntu-18.04'
steps:
- checkout: none
- download: current
artifact: files
- pwsh: $PSVersionTable | Out-String
displayName: PSVersionTable
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/'
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -MinimumVersion 5.0 -Repository PSGallery -Confirm:$false
Import-Module -Name './Pester/'
Get-Module Pester | Select Version, Name
Set-Location -Path '$(Pipeline.Workspace)'
Invoke-Pester -CI
displayName: Pester
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'testResults.xml'
searchFolder: $(Pipeline.Workspace)
mergeTestResults: true
buildPlatform: Ubuntu 18.04

- job: Windows_2019_Pwsh
pool:
vmImage: 'windows-2019'
steps:
- checkout: none
- download: current
artifact: files
- pwsh: $PSVersionTable | Out-String
displayName: PSVersionTable
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/'
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -MinimumVersion 5.0 -Repository PSGallery -Confirm:$false
Import-Module -Name './Pester/'
Get-Module Pester | Select Version, Name
Set-Location -Path '$(Pipeline.Workspace)'
Invoke-Pester -CI
displayName: Pester
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'testResults.xml'
searchFolder: $(Pipeline.Workspace)
mergeTestResults: true
buildPlatform: Windows Server 2019
- template: build-steps.yml
parameters:
moduleName: ${{ variables.moduleName }}

- job: Windows_2016_Pwsh
pool:
vmImage: 'vs2017-win2016'
steps:
- checkout: none
- download: current
artifact: files
- pwsh: $PSVersionTable | Out-String
displayName: PSVersionTable
- pwsh: |
Save-Module -Name PSScriptAnalyzer -Path '.' -Repository PSGallery -Confirm:$false
Resolve-Path -Path './PSScriptAnalyzer/*/PSScriptAnalyzer.psd1' | Import-Module
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
displayName: Script Analyzer
- pwsh: |
Save-Module -Name Pester -Path '.' -MinimumVersion 5.0 -Repository PSGallery -Confirm:$false
Resolve-Path -Path './Pester/*/Pester.psd1' | Import-Module
Set-Location -Path '$(Pipeline.Workspace)'
Invoke-Pester -CI
displayName: Pester
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'testResults.xml'
searchFolder: $(Pipeline.Workspace)
mergeTestResults: true
buildPlatform: Windows Server 2016
- template: test-stage.yml
parameters:
PS51: false

- stage: Deploy
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
Expand All @@ -193,8 +40,8 @@ stages:
- download: current
artifact: files
- pwsh: |
Move-Item -Path '$(Pipeline.Workspace)/files/PwshTenable.psd1' -Destination 'PwshTenable.psd1' -Confirm:$false -Force
git add PwshTenable.psd1
Move-Item -Path '$(Pipeline.Workspace)/files/${{ variables.moduleName }}.psd1' -Destination '${{ variables.moduleName }}.psd1' -Confirm:$false -Force
git add ${{ variables.moduleName }}.psd1
git -c "user.name=$(Build.RequestedFor)" -c "user.email=$(Build.RequestedForEmail)" commit -m "Updated module version: $(Build.BuildNumber) [skip ci]"
git push origin HEAD:master
workingDirectory: '$(Build.SourcesDirectory)'
Expand All @@ -207,7 +54,7 @@ stages:
inputs:
target: master
gitHubConnection: RobFaie
repositoryName: telstrapurple/PwshTenable
repositoryName: telstrapurple/${{ variables.moduleName }}
tagSource: manual
tag: $(Build.BuildNumber)
assets: |
Expand Down
46 changes: 46 additions & 0 deletions build-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
parameters:
- name: moduleName
type: string

steps:
- script: dotnet tool install --global GitVersion.Tool --version 5.3.3
displayName: Install Gitversion
- pwsh: |
$raw = dotnet-gitversion
Write-Host $raw
$version = $raw | ConvertFrom-Json | ForEach-Object MajorMinorPatch
Write-Host "##vso[build.updatebuildnumber]$version"
displayName: Set Build Number
- pwsh: |
$rawManifest = Get-Content -Path "${{ parameters.moduleName }}.psd1" -raw
$updatedManifest = $rawManifest -replace "ModuleVersion\s*=\s*['`"][0-9.]+['`"]", "ModuleVersion = '$(Build.BuildNumber)'"
$updatedManifest | Out-File -Path "${{ parameters.moduleName }}.psd1" -NoNewline
displayName: Update Module Manifest Version Number
- task: CopyFiles@2
inputs:
contents: |
**/*
!**/.*/**/*
!**/.*
!*.yml
targetFolder: $(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}
- publish: '$(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}'
artifact: 'files'
displayName: 'Publish Artifact files'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}
archiveFile: '$(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}_$(Build.BuildNumber).zip'
displayName: 'Archive zip'
- publish: '$(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}_$(Build.BuildNumber).zip'
artifact: 'zip'
displayName: 'Publish Artifact zip'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: $(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}
archiveType: tar
archiveFile: '$(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}_$(Build.BuildNumber).tar.gz'
displayName: 'Archive tar'
- publish: '$(Build.ArtifactStagingDirectory)/${{ parameters.moduleName }}_$(Build.BuildNumber).tar.gz'
artifact: 'tar'
displayName: 'Publish Artifact tar'
51 changes: 51 additions & 0 deletions test-stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
parameters:
- name: PS51
type: boolean
default: true

stages:
- stage: Test
jobs:

- job: Mac_10_14
pool:
vmImage: 'macOS-10.14'
steps:
- template: test-steps.yml
parameters:
testRunTitle: Mac 10.14

- job: Ubuntu_18_04
pool:
vmImage: 'ubuntu-18.04'
steps:
- template: test-steps.yml
parameters:
testRunTitle: Ubuntu 18.04

- job: Windows_2019_Pwsh
pool:
vmImage: 'windows-2019'
steps:
- template: test-steps.yml
parameters:
testRunTitle: Windows Server 2019

- ${{ if eq(parameters.PS51, false) }}:
- job: Windows_2016_Pwsh
pool:
vmImage: 'vs2017-win2016'
steps:
- template: test-steps.yml
parameters:
testRunTitle: Windows Server 2016

- ${{ if eq(parameters.PS51, true) }}:
- job: Windows_2016_Powershell
pool:
vmImage: 'vs2017-win2016'
steps:
- template: test-steps.yml
parameters:
testRunTitle: Windows Server 2016
pwsh: false
52 changes: 52 additions & 0 deletions test-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
parameters:
- name: testRunTitle
type: string
- name: pwsh
type: boolean
default: true

steps:
- checkout: none
- download: current
artifact: files
- task: PowerShell@2
displayName: PSVersionTable
inputs:
targetType: inline
pwsh: ${{ parameters.pwsh }}
script: $PSVersionTable | Out-String
- task: PowerShell@2
displayName: Script Analyzer
inputs:
targetType: inline
pwsh: ${{ parameters.pwsh }}
script: |
Save-Module -Name PSScriptAnalyzer -Path '.' -MinimumVersion 1.0 -MaximumVersion 1.999 -Repository PSGallery -Confirm:$false
Import-Module -Name './PSScriptAnalyzer/*/PSScriptAnalyzer.psd1'
Get-Module PSScriptAnalyzer | Select Version, Name
Get-ChildItem -Path '$(Pipeline.Workspace)' -Directory | Invoke-ScriptAnalyzer -EnableExit | Format-Table -AutoSize
- task: PowerShell@2
displayName: Pester
inputs:
targetType: inline
pwsh: ${{ parameters.pwsh }}
script: |
Save-Module -Name Pester -Path '.' -MinimumVersion 5.0 -MaximumVersion 5.999 -Repository PSGallery -Confirm:$false
Import-Module -Name './Pester/*/Pester.psd1'
Get-Module Pester | Format-Table Name, Version | Out-String
Set-Location -Path '$(Pipeline.Workspace)'
Invoke-Pester -CI
Get-ChildItem *.xml | Out-String
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: 'testResults.xml'
searchFolder: $(Pipeline.Workspace)
testRunTitle: ${{ parameters.testRunTitle }}
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: JaCoCo
summaryFileLocation: $(Pipeline.Workspace)/coverage.xml
reportDirectory: $(Pipeline.Workspace)
pathToSources: $(Pipeline.Workspace)

0 comments on commit f4fb748

Please sign in to comment.