Skip to content

Commit 4e3f061

Browse files
committed
Update module path
1 parent 45bcebe commit 4e3f061

File tree

5 files changed

+78
-37
lines changed

5 files changed

+78
-37
lines changed
Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,47 @@
11
trigger:
22
branches:
33
include:
4-
- main
4+
- main
55

66
stages:
77
- stage: build
88
jobs:
99
- job: Build
10-
displayName: "Build AppLocker Artifacts"
10+
displayName: 'Build AppLocker Artifacts'
1111
pool:
1212
name: Default
1313
workspace:
1414
clean: all
1515
steps:
1616
- task: PowerShell@2
1717
name: prereq
18-
displayName: "Download prerequisites"
18+
displayName: 'Download prerequisites'
1919
inputs:
2020
filePath: '.\build\prerequisites.ps1'
21+
arguments: '-DependencyPath .\build\requiredModules.psd1'
2122
- task: PowerShell@2
2223
name: validateyaml
2324
displayName: Validate Configuration Data
2425
inputs:
2526
filePath: '.\build\validate.ps1'
26-
arguments: "-TestType ConfigurationData"
27+
arguments: '-TestType ConfigurationData -DependencyPath .\build\requiredModules.psd1'
2728
- task: PowerShell@2
2829
name: buildpolicy
2930
displayName: Build policy XML
3031
inputs:
3132
filePath: '.\build\build.ps1'
32-
arguments: "-IncludeRsop"
33+
arguments: '-IncludeRsop -DependencyPath .\build\requiredModules.psd1'
34+
3335
- task: PublishBuildArtifacts@1
34-
displayName: "Publish Policy XML Files"
36+
displayName: 'Publish Policy XML Files'
3537
inputs:
36-
PathtoPublish: "output/Policies"
38+
PathtoPublish: 'output/Policies'
3739
ArtifactName: Policies
40+
3841
- task: PublishBuildArtifacts@1
39-
displayName: "Publish Policy RSOP Files"
42+
displayName: 'Publish Policy RSOP Files'
4043
inputs:
41-
PathtoPublish: "output/Rsop"
44+
PathtoPublish: 'output/Rsop'
4245
ArtifactName: Rsop
4346
- stage: publish
4447
dependsOn: build
@@ -54,28 +57,29 @@ stages:
5457
runOnce:
5558
deploy:
5659
steps:
57-
- download: None
58-
- task: DownloadBuildArtifacts@0
59-
displayName: "Download Build Artifact: Rsop"
60-
inputs:
61-
buildType: "current"
62-
artifactName: Rsop
63-
downloadPath: $(Build.SourcesDirectory)
64-
- task: DownloadBuildArtifacts@0
65-
displayName: "Download Build Artifact: Policies"
66-
inputs:
67-
buildType: "current"
68-
artifactName: Policies
69-
downloadPath: $(Build.SourcesDirectory)
70-
- task: PowerShell@2
71-
name: publishpolicies
72-
displayName: Publish policies
73-
inputs:
74-
filePath: '.\build\publish.ps1'
75-
arguments: "-OutputPath $(Build.SourcesDirectory)"
76-
- task: PowerShell@2
77-
name: validateintegration
78-
displayName: Validate Integration
79-
inputs:
80-
filePath: '.\build\validate.ps1'
81-
arguments: "-TestType Integration"
60+
- download: None
61+
62+
- task: DownloadBuildArtifacts@0
63+
displayName: 'Download Build Artifact: Rsop'
64+
inputs:
65+
buildType: 'current'
66+
artifactName: Rsop
67+
downloadPath: $(Build.SourcesDirectory)
68+
- task: DownloadBuildArtifacts@0
69+
displayName: 'Download Build Artifact: Policies'
70+
inputs:
71+
buildType: 'current'
72+
artifactName: Policies
73+
downloadPath: $(Build.SourcesDirectory)
74+
- task: PowerShell@2
75+
name: publishpolicies
76+
displayName: Publish policies
77+
inputs:
78+
filePath: '.\build\publish.ps1'
79+
arguments: '-OutputPath $(Build.SourcesDirectory) -DependencyPath .\build\requiredModules.psd1'
80+
- task: PowerShell@2
81+
name: validateintegration
82+
displayName: Validate Integration
83+
inputs:
84+
filePath: '.\build\validate.ps1'
85+
arguments: '-TestType Integration -DependencyPath .\build\requiredModules.psd1'

templates/AppLockerProject/build/build.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
param
33
(
4+
[string]
5+
$DependencyPath = (Resolve-Path "$PSScriptRoot\requiredModules.psd1").Path,
6+
47
[string]
58
$SourcePath = "$PSScriptRoot\..\configurationdata",
69

@@ -11,6 +14,12 @@ param
1114
$IncludeRsop
1215
)
1316

17+
$psdependConfig = Import-PowerShellDataFile -Path $DependencyPath
18+
$modPath = Resolve-Path -Path $psdependConfig.PSDependOptions.Target
19+
$modOld = $env:PSModulePath
20+
$pathSeparator = [System.IO.Path]::PathSeparator
21+
$env:PSModulePath = "$modPath$pathSeparator$modOld"
22+
1423
$SourcePath = Resolve-Path -Path $SourcePath -ErrorAction Stop
1524
$OutputPath = if (-not (Resolve-Path -Path $OutputPath -ErrorAction SilentlyContinue))
1625
{
@@ -42,7 +51,11 @@ $datum = New-DatumStructure -DefinitionFile (Join-Path $SourcePath Datum.yml)
4251
$rsops = Get-DatumRsop $datum (Get-DatumNodesRecursive -AllDatumNodes $Datum.AllNodes)
4352
$rsops | Export-AlfXml -Path $policyPath
4453

45-
if (-not $IncludeRsop) { return }
54+
if (-not $IncludeRsop)
55+
{
56+
$env:PSModulePath = $modOld
57+
return
58+
}
4659

4760
foreach ($rsop in $rsops)
4861
{
@@ -53,3 +66,5 @@ foreach ($rsop in $rsops)
5366
}
5467
$rsop | ConvertTo-Yaml -OutFile (Join-Path -Path $domainPath -ChildPath "$($rsop.PolicyName).yml") -Force
5568
}
69+
70+
$env:PSModulePath = $modOld

templates/AppLockerProject/build/publish.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
param
22
(
3+
[string]
4+
$DependencyPath = (Resolve-Path "$PSScriptRoot\requiredModules.psd1").Path,
5+
36
[string]
47
$OutputPath = (Resolve-Path "$PSScriptRoot\..\output").Path
58
)
69

10+
$psdependConfig = Import-PowerShellDataFile -Path $DependencyPath
11+
$modPath = Resolve-Path -Path $psdependConfig.PSDependOptions.Target
12+
$modOld = $env:PSModulePath
13+
$pathSeparator = [System.IO.Path]::PathSeparator
14+
$env:PSModulePath = "$modPath$pathSeparator$modOld"
15+
716
foreach ($policy in (Get-ChildItem -Path (Join-Path -Path $OutputPath -ChildPath Policies) -Recurse -Filter *.xml))
817
{
918
$searcher = [adsisearcher]::new()
@@ -19,3 +28,5 @@ foreach ($policy in (Get-ChildItem -Path (Join-Path -Path $OutputPath -ChildPath
1928

2029
Set-AppLockerPolicy -XmlPolicy $policy.FullName -Ldap $policyFound.Path
2130
}
31+
32+
$env:PSModulePath = $modOld

templates/AppLockerProject/build/requiredModules.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
PSDependOptions = @{
3-
AddToPath = $true
3+
AddToPath = $false
44
Target = 'output\RequiredModules'
55
Parameters = @{
66
Repository = 'PSGallery'

templates/AppLockerProject/build/validate.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[CmdletBinding()]
22
param
33
(
4+
[string]
5+
$DependencyPath = (Resolve-Path "$PSScriptRoot\requiredModules.psd1").Path,
6+
47
[string]
58
$ProjectRoot = (Resolve-Path "$PSScriptRoot\..").Path,
69

@@ -9,7 +12,13 @@ param
912
$TestType
1013
)
1114

12-
Import-Module Pester
15+
$psdependConfig = Import-PowerShellDataFile -Path $DependencyPath
16+
$modPath = Resolve-Path -Path $psdependConfig.PSDependOptions.Target
17+
$modOld = $env:PSModulePath
18+
$pathSeparator = [System.IO.Path]::PathSeparator
19+
$env:PSModulePath = "$modPath$pathSeparator$modOld"
20+
21+
Import-Module Pester -Force -ErrorAction Stop -MinimumVersion 5.0.0
1322

1423
$global:testroot = Join-Path $ProjectRoot tests
1524
$po = [PesterConfiguration]::New()
@@ -21,6 +30,8 @@ $po.TestResult.OutputPath = Join-Path $global:testroot 'testresults.xml'
2130
$po.TestResult.OutputFormat = 'NUnit2.5'
2231

2332
$result = Invoke-Pester -Configuration $po
33+
$env:PSModulePath = $modOld
34+
2435
if ($result.FailedCount -gt 0) {
2536
throw "Pester tests failed"
2637
}

0 commit comments

Comments
 (0)