-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
219 lines (186 loc) · 8.97 KB
/
Copy pathazure-pipelines.yml
File metadata and controls
219 lines (186 loc) · 8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Azure DevOps Pipeline for Ad-Audit
# Author: Adrian Johnson
trigger:
branches:
include:
- main
- develop
paths:
include:
- 'Modules/**'
- 'Libraries/**'
- 'Tests/**'
- '*.ps1'
pr:
branches:
include:
- main
- develop
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
stages:
- stage: Test
displayName: 'Test Stage'
jobs:
- job: PesterTests
displayName: 'Run Pester Tests'
steps:
- checkout: self
displayName: 'Checkout code'
- pwsh: |
Write-Host "PowerShell Version: $($PSVersionTable.PSVersion)"
Write-Host "OS: $($PSVersionTable.OS)"
displayName: 'Display Environment Info'
- pwsh: |
Write-Host "Installing Pester 5.x..."
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.0.0
Import-Module Pester -PassThru
displayName: 'Install Pester'
- pwsh: |
cd Tests
$result = ./RunTests.ps1 -OutputFormat NUnitXml -CodeCoverage -PassThru
# Output results for pipeline
Write-Host "##vso[task.setvariable variable=TestsPassed]$($result.PassedCount)"
Write-Host "##vso[task.setvariable variable=TestsFailed]$($result.FailedCount)"
Write-Host "##vso[task.setvariable variable=TestsTotal]$($result.TotalCount)"
if ($result.FailedCount -gt 0) {
Write-Error "##vso[task.logissue type=error]$($result.FailedCount) test(s) failed"
exit 1
}
displayName: 'Run Pester Tests'
continueOnError: 'false'
- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: always()
inputs:
testResultsFormat: 'NUnit'
testResultsFiles: '**/TestResults.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/Tests'
mergeTestResults: true
testRunTitle: 'Pester Tests'
failTaskOnFailedTests: true
# Note: PublishCodeCoverageResults@1 is deprecated by Azure DevOps
# Enable if code coverage publishing is required (task still functional)
# - task: PublishCodeCoverageResults@1
# displayName: 'Publish Code Coverage'
# condition: always()
# inputs:
# codeCoverageTool: 'JaCoCo'
# summaryFileLocation: '$(System.DefaultWorkingDirectory)/Tests/coverage.xml'
# reportDirectory: '$(System.DefaultWorkingDirectory)/Tests/TestResults'
# failIfCoverageEmpty: false
- pwsh: |
Write-Host "Test Summary:" -ForegroundColor Cyan
Write-Host " Total: $(TestsTotal)" -ForegroundColor White
Write-Host " Passed: $(TestsPassed)" -ForegroundColor Green
Write-Host " Failed: $(TestsFailed)" -ForegroundColor $(if([int]$env:TESTSFAILED -gt 0){'Red'}else{'Green'})
displayName: 'Display Test Summary'
condition: always()
- job: ScriptAnalyzer
displayName: 'PowerShell Script Analyzer'
steps:
- checkout: self
displayName: 'Checkout code'
- pwsh: |
Write-Host "Installing PSScriptAnalyzer..."
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
displayName: 'Install PSScriptAnalyzer'
- pwsh: |
Write-Host "Running PSScriptAnalyzer..."
$results = Invoke-ScriptAnalyzer `
-Path $(System.DefaultWorkingDirectory) `
-Recurse `
-Settings PSGallery `
-Severity Error,Warning `
-ExcludeRule PSAvoidUsingWriteHost
if ($results) {
Write-Host "Issues found:" -ForegroundColor Yellow
$results | Format-Table -AutoSize
$errorCount = ($results | Where-Object Severity -eq 'Error').Count
$warningCount = ($results | Where-Object Severity -eq 'Warning').Count
Write-Host ""
Write-Host "Summary:" -ForegroundColor Cyan
Write-Host " Errors: $errorCount" -ForegroundColor $(if($errorCount -gt 0){'Red'}else{'Green'})
Write-Host " Warnings: $warningCount" -ForegroundColor Yellow
# Set variables for reporting
Write-Host "##vso[task.setvariable variable=LintErrors]$errorCount"
Write-Host "##vso[task.setvariable variable=LintWarnings]$warningCount"
if ($errorCount -gt 0) {
Write-Host "##vso[task.logissue type=error]Found $errorCount error(s)"
exit 1
}
} else {
Write-Host "✓ No issues found!" -ForegroundColor Green
Write-Host "##vso[task.setvariable variable=LintErrors]0"
Write-Host "##vso[task.setvariable variable=LintWarnings]0"
}
displayName: 'Run Script Analyzer'
continueOnError: 'false'
- stage: Package
displayName: 'Package Stage'
dependsOn: Test
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- job: CreatePackage
displayName: 'Create PowerShell Module Package'
steps:
- checkout: self
displayName: 'Checkout code'
- pwsh: |
Write-Host "Creating module package..."
$modulePath = "$(Build.ArtifactStagingDirectory)/AD-Audit"
# Create module directory structure
New-Item -ItemType Directory -Path $modulePath -Force
New-Item -ItemType Directory -Path "$modulePath/Modules" -Force
New-Item -ItemType Directory -Path "$modulePath/Libraries" -Force
New-Item -ItemType Directory -Path "$modulePath/Utilities" -Force
New-Item -ItemType Directory -Path "$modulePath/Tests" -Force
New-Item -ItemType Directory -Path "$modulePath/docs" -Force
New-Item -ItemType Directory -Path "$modulePath/wwwroot" -Force
# Copy files
Copy-Item -Path "*.ps1" -Destination $modulePath -Force
Copy-Item -Path "*.psd1" -Destination $modulePath -Force -ErrorAction SilentlyContinue
Copy-Item -Path "*.md" -Destination $modulePath -Force
Copy-Item -Path "Modules/*" -Destination "$modulePath/Modules/" -Recurse -Force
Copy-Item -Path "Libraries/*" -Destination "$modulePath/Libraries/" -Recurse -Force
Copy-Item -Path "Utilities/*" -Destination "$modulePath/Utilities/" -Recurse -Force
Copy-Item -Path "Tests/*" -Destination "$modulePath/Tests/" -Recurse -Force
Copy-Item -Path "docs/*" -Destination "$modulePath/docs/" -Recurse -Force
Copy-Item -Path "wwwroot/*" -Destination "$modulePath/wwwroot/" -Recurse -Force
Write-Host "✓ Module package created at: $modulePath" -ForegroundColor Green
displayName: 'Package Module'
- task: PublishBuildArtifacts@1
displayName: 'Publish Module Artifact'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'AD-Audit-Module'
publishLocation: 'Container'
- pwsh: |
Write-Host "Build Summary:" -ForegroundColor Cyan
Write-Host " Branch: $(Build.SourceBranchName)" -ForegroundColor White
Write-Host " Commit: $(Build.SourceVersion)" -ForegroundColor White
Write-Host " Build: $(Build.BuildNumber)" -ForegroundColor White
displayName: 'Build Summary'
- stage: Notify
displayName: 'Notification Stage'
dependsOn: [Test, Package]
condition: always()
jobs:
- job: SendNotification
displayName: 'Send Build Notification'
steps:
- pwsh: |
$status = if ('${{ dependencies.Test.result }}' -eq 'Succeeded' -and '${{ dependencies.Package.result }}' -eq 'Succeeded') {
"✓ SUCCESS"
} else {
"✗ FAILED"
}
Write-Host "Build Status: $status" -ForegroundColor $(if($status -like '*SUCCESS*'){'Green'}else{'Red'})
Write-Host "Pipeline: $(Build.DefinitionName)" -ForegroundColor Cyan
Write-Host "Build: $(Build.BuildNumber)" -ForegroundColor Cyan
Write-Host "Branch: $(Build.SourceBranchName)" -ForegroundColor Cyan
displayName: 'Build Status'