Skip to content

Commit 0b8eb71

Browse files
author
Friedrich Weinmann
committed
updates
1 parent 5b33561 commit 0b8eb71

File tree

13 files changed

+341
-41
lines changed

13 files changed

+341
-41
lines changed
Binary file not shown.
Binary file not shown.

PSModuleDevelopment/bin/PSModuleDevelopment.xml

Lines changed: 150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSModuleDevelopment/functions/build/Invoke-PSMDBuildProject.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@
154154
Parameters = $step.Parameters | ConvertTo-PSFHashtable
155155
ProjectName = $projectObject.Name
156156
StepName = $step.Name
157+
ParametersFromArtifacts = $step.ParametersFromArtifacts | ConvertTo-PSFHashtable
157158
}
158159
if (-not $parameters.Parameters) { $parameters.Parameters = @{ } }
160+
if (-not $parameters.ParametersFromArtifacts) { $parameters.ParametersFromArtifacts = @{ } }
159161
try { $null = & $actionObject.Action $parameters }
160162
catch {
161163
Write-StepResult @resultDef -Status Failed -Data $_ -ContinueLabel main

PSModuleDevelopment/functions/build/Resolve-PSMDBuildStepParameter.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
The hashtable containing the currently specified parameters from the step configuration within the build project file.
1212
Only settings not already defined there are taken from configuration.
1313
14+
.PARAMETER FromArtifacts
15+
The hashtable mapping parameters from artifacts.
16+
This allows dynamically assigning artifacts to parameters.
17+
1418
.PARAMETER ProjectName
1519
The name of the project being executed.
1620
Supplementary parameters taken from configuration will pick up settings based on this name:
@@ -23,7 +27,7 @@
2327
2428
.EXAMPLE
2529
PS C:\> Resolve-PSMDBuildStepParameter -Parameters $actualParameters -ProjectName VMDeployment -StepName 'Create Session'
26-
30+
2731
Adds parameters provided through configuration.
2832
#>
2933
[CmdletBinding()]
@@ -32,6 +36,10 @@
3236
[hashtable]
3337
$Parameters,
3438

39+
[Parameter(Mandatory = $true)]
40+
[hashtable]
41+
$FromArtifacts,
42+
3543
[Parameter(Mandatory = $true)]
3644
[string]
3745
$ProjectName,
@@ -42,15 +50,19 @@
4250
)
4351

4452
process {
53+
# Process parameters from Configuration
4554
$configObject = Select-PSFConfig -FullName "PSModuleDevelopment.BuildParam.$ProjectName.$StepName.*"
46-
if (-not $configObject) { return $Parameters }
47-
4855
foreach ($property in $configObject.PSObject.Properties) {
4956
if ($property.Name -in '_Name', '_FullName', '_Depth', '_Children') { continue }
5057
if ($Parameters.ContainsKey($property.Name)) { continue }
5158
$Parameters[$property.Name] = $property.Value
5259
}
5360

61+
# Process parameters from Artifacts
62+
foreach ($pair in $FromArtifacts.GetEnumerator()) {
63+
$Parameters[$pair.Key] = (Get-PSMDBuildArtifact -Name $pair.Value).Value
64+
}
65+
5466
$Parameters
5567
}
5668
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
$action = {
2+
param (
3+
$Parameters
4+
)
5+
6+
$rootPath = $Parameters.RootPath
7+
$actualParameters = $Parameters.Parameters
8+
$actualParameters = Resolve-PSMDBuildStepParameter -Parameters $actualParameters -FromArtifacts $Parameters.ParametersFromArtifacts -ProjectName $Parameters.ProjectName -StepName $Parameters.StepName
9+
10+
#region Process Parameters
11+
if (-not $actualParameters.Command) {
12+
throw "Mandatory parameter: Command not specified"
13+
}
14+
15+
if ($actualParameters.Command -is [System.Management.Automation.ScriptBlock]) {
16+
$scriptblock = $actualParameters.Command
17+
}
18+
else {
19+
try { $scriptblock = [scriptblock]::Create($actualParameters.Command) }
20+
catch {
21+
throw "Error parsing command '$($actualParameters.Command)' : $_"
22+
}
23+
}
24+
25+
$actualArguments = foreach ($argument in $actualParameters.ArgumentList) {
26+
if ($argument -isnot [string]) {
27+
$argument
28+
continue
29+
}
30+
if ($argument -notlike '%!*!%') {
31+
$argument
32+
continue
33+
}
34+
$artifactName = $argument -replace '^%!(.+)!%$', '$1'
35+
$artifactObject = Get-PSMDBuildArtifact -Name $artifactName
36+
if (-not $artifactObject) { throw "Artifact for arguments not found: $artifactName" }
37+
$artifactObject.Value
38+
}
39+
40+
$inSession = $null
41+
if ($actualParameters.InSession) {
42+
if ($actualParameters.InSession -is [System.Management.Automation.Runspaces.PSSession]) {
43+
$inSession = $actualParameters.InSession
44+
}
45+
$artifactObject = Get-PSMDBuildArtifact -Name $actualParameters.InSession
46+
if (-not $artifactObject) { throw "Artifact for parameter InSession not found: $($actualParameters.InSession)" }
47+
if ($artifactObject.Value -isnot [System.Management.Automation.Runspaces.PSSession]) { throw "Artifact for parameter InSession ($($actualParameters.InSession)) is not a pssession!" }
48+
$inSession = $artifactObject.Value
49+
}
50+
#endregion Process Parameters
51+
52+
#region Execution
53+
$invokeParam = @{
54+
ScriptBlock = $scriptblock
55+
ArgumentList = $actualArguments
56+
}
57+
if ($inSession) { $invokeParam.Session = $inSession }
58+
try { Invoke-Command @invokeParam -ErrorAction Stop }
59+
catch { throw }
60+
#endregion Execution
61+
}
62+
63+
$params = @{
64+
Name = 'command'
65+
Action = $action
66+
Description = 'Execute a scriptblock'
67+
Parameters = @{
68+
Command = '(mandatory) Scriptcode to run'
69+
ArgumentList = 'Any number of arguments to pass to the command. To insert artifacts, specify a string with the special notation "%!ArtifactName!%"'
70+
InSession = 'Execute the scriptfile in the target PSSession. Either provide a full session object or an artifact name pointing at one.'
71+
}
72+
}
73+
74+
Register-PSMDBuildAction @params

PSModuleDevelopment/internal/buildActions/copy-item.action.ps1

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@
55

66
$rootPath = $Parameters.RootPath
77
$actualParameters = $Parameters.Parameters
8-
$actualParameters = Resolve-PSMDBuildStepParameter -Parameters $actualParameters -ProjectName $Parameters.ProjectName -StepName $Parameters.StepName
8+
$actualParameters = Resolve-PSMDBuildStepParameter -Parameters $actualParameters -FromArtifacts $Parameters.ParametersFromArtifacts -ProjectName $Parameters.ProjectName -StepName $Parameters.StepName
9+
10+
#region Utility Functions
11+
function ConvertTo-PSSession {
12+
[CmdletBinding()]
13+
param (
14+
[Parameter(ValueFromPipeline = $true)]
15+
$InputObject
16+
)
17+
process {
18+
if ($InputObject -is [System.Management.Automation.Runspaces.PSSession]) {
19+
return $InputObject
20+
}
21+
$artifactValue = (Get-PSMDBuildArtifact -Name $InputObject).Value
22+
if ($artifactValue -is [System.Management.Automation.Runspaces.PSSession]) {
23+
return $artifactValue
24+
}
25+
}
26+
}
27+
#endregion Utility Functions
928

1029
if (-not ($actualParameters.Path -and $actualParameters.Destination)) {
1130
throw "Invalid parameters! Specify both Path and Destination."
@@ -18,18 +37,18 @@
1837
if ($actualParameters.Recurse) { $copyParam.Recurse = $true }
1938
if ($actualParameters.Force) { $copyParam.Force = $true }
2039
if ($actualParameters.FromSession) {
21-
$artifact = Get-PSMDBuildArtifact -Name $actualParameters.FromSession
22-
if (-not $artifact) {
40+
$fromSession = $actualParameters.FromSession | ConvertTo-PSSession
41+
if (-not $fromSession) {
2342
throw "FromSession $($actualParameters.FromSession) not found!"
2443
}
25-
$copyParam.FromSession = $artifact.Value
44+
$copyParam.FromSession = $fromSession
2645
}
2746
if ($actualParameters.ToSession) {
28-
$artifact = Get-PSMDBuildArtifact -Name $actualParameters.ToSession
29-
if (-not $artifact) {
47+
$toSession = $actualParameters.ToSession | ConvertTo-PSSession
48+
if (-not $toSession) {
3049
throw "ToSession $($actualParameters.ToSession) not found!"
3150
}
32-
$copyParam.ToSession = $artifact.Value
51+
$copyParam.ToSession = $toSession
3352
}
3453
foreach ($path in $paths) {
3554
try { Copy-Item @copyParam -Path $path -ErrorAction Stop }

PSModuleDevelopment/internal/buildActions/new-pssession.action.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
$rootPath = $Parameters.RootPath
77
$actualParameters = $Parameters.Parameters
8-
$actualParameters = Resolve-PSMDBuildStepParameter -Parameters $actualParameters -ProjectName $Parameters.ProjectName -StepName $Parameters.StepName
8+
$actualParameters = Resolve-PSMDBuildStepParameter -Parameters $actualParameters -FromArtifacts $Parameters.ParametersFromArtifacts -ProjectName $Parameters.ProjectName -StepName $Parameters.StepName
99

1010
if (-not $actualParameters.ArtifactName) { throw "No ArtifactName specified! Unable to publish remoting session for build." }
1111
if (-not ($actualParameters.VMName -or $actualParameters.ComputerName)) { throw "Neither ComputerName nor VMName specified, unable to connect to nothing!" }

0 commit comments

Comments
 (0)