Repository navigation
Expand file tree
/
Copy pathSet-PSMDBuildStep.ps1
More file actions
120 lines (99 loc) · 3.93 KB
/
Copy pathSet-PSMDBuildStep.ps1
File metadata and controls
120 lines (99 loc) · 3.93 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
function Set-PSMDBuildStep {
<#
.SYNOPSIS
Create or update a step from a build project.
.DESCRIPTION
Create or update a step from a build project.
.PARAMETER Name
The name of the step.
All step names must be unique within a single build project.
.PARAMETER Weight
The weight of the step.
Weight determines processing order, the lower the number the earlier it is executed.
.PARAMETER Action
The name of the action to execute.
Use Get-PSMDBuildAction to get a list of available actions.
.PARAMETER Parameters
The parameters this action should take.
See the action object to see a description of parameters, including which must be provided and which can be skipped.
.PARAMETER Condition
A PSFramework filter condition that must apply for this action to be executed successfully.
Example Conditions:
Elevated
PS7Plus -and OSWindows
More Details: https://psframework.org/documentation/documents/psframework/filters.html
.PARAMETER ConditionSet
The name of the condition set to use.
This is part of the PSFramework filter system:
https://psframework.org/documentation/documents/psframework/filters.html
Specify as "<module> <conditionsetname>" format.
Default Value: PSFramework Environment
.PARAMETER Dependency
Any other steps that must successfully finished in order for this step to execute.
ALL of the listed steps must have succeeded, skipped steps do not count.
.PARAMETER BuildProject
The build project file to work against.
Specify the full path to the build project file.
This parameter can be skipped if a default project file has been defined.
.EXAMPLE
PS C:\> Set-PSMDBuildStep -Name 'Create Session' -Action new-pssession -Parameters @{ VMName = 'labdc1'; CredentialPath = "%ProjectRoot%\creds\labdc1.cred"; }
Defines a new step named 'Create Session' using the 'new-pssession'-action.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Name,
[int]
$Weight,
[PsfArgumentCompleter('PSModuleDevelopment.Build.Action')]
[string]
$Action,
[hashtable]
$Parameters,
[string]
$Condition,
[string]
$ConditionSet,
[string[]]
$Dependency,
[string]
$BuildProject
)
begin {
$projectPath = $BuildProject
if (-not $projectPath) { $projectPath = Get-PSFConfigValue -FullName 'PSModuleDevelopment.Build.Project.Selected' }
if (-not $projectPath) { throw "No Project path specified and none selected!" }
if (-not (Test-Path -Path $projectPath)) {
throw "Project file not found: $projectPath"
}
}
process {
$projectObject = Get-PSMDBuildProject -Path $projectPath | ConvertTo-PSFHashtable
$stepObject = $projectObject.Steps | Where-Object Name -EQ $Name | ConvertTo-PSFHashtable
if (-not $stepObject) {
$stepObject = [pscustomobject]@{
PSTypeName = 'PSModuleDevelopment.Build.Step'
Name = $Name
Weight = 50
Action = ''
Parameters = @{ }
Condition = ''
ConditionSet = 'PSFramework Environment'
Dependency = @()
}
}
if (Test-PSFParameterBinding -ParameterName Weight) { $stepObject.Weight = $Weight }
if (Test-PSFParameterBinding -ParameterName Action) { $stepObject.Action = $Action }
if (Test-PSFParameterBinding -ParameterName Parameters) { $stepObject.Parameters = $Parameters }
if (Test-PSFParameterBinding -ParameterName Condition) { $stepObject.Condition = $Condition }
if (Test-PSFParameterBinding -ParameterName ConditionSet) { $stepObject.ConditionSet = $ConditionSet }
if (Test-PSFParameterBinding -ParameterName Dependency) { $stepObject.Dependency = $Dependency }
if (-not $stepObject.Action) {
throw "Failed to save Build Step $Name : No Action defined!"
}
$projectObject.Steps = @($projectObject.Steps | Where-Object Name -ne $Name) + @($stepObject)
$projectObject | Export-PsmdBuildProjectFile -OutPath $projectPath -ErrorAction Stop
}
}