-
Notifications
You must be signed in to change notification settings - Fork 4
/
TaskSetup.ps1
102 lines (78 loc) · 2.2 KB
/
TaskSetup.ps1
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
function TaskSetup {
<#
.SYNOPSIS
Adds a scriptblock that will be executed before each task
.DESCRIPTION
This function will accept a scriptblock that will be executed before each task in the build script.
The scriptblock accepts an optional parameter which describes the Task being setup.
.PARAMETER setup
A scriptblock to execute
.EXAMPLE
A sample build script is shown below:
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
TaskSetup {
"Running 'TaskSetup' for task $context.Peek().currentTaskName"
}
The script above produces the following output:
Running 'TaskSetup' for task Clean
Executing task, Clean...
Running 'TaskSetup' for task Compile
Executing task, Compile...
Running 'TaskSetup' for task Test
Executing task, Test...
Build Succeeded
.EXAMPLE
A sample build script showing access to the Task context is shown below:
Task default -depends Test
Task Test -depends Compile, Clean {
}
Task Compile -depends Clean {
}
Task Clean {
}
TaskSetup {
param($task)
"Running 'TaskSetup' for task $($task.Name)"
}
The script above produces the following output:
Running 'TaskSetup' for task Clean
Executing task, Clean...
Running 'TaskSetup' for task Compile
Executing task, Compile...
Running 'TaskSetup' for task Test
Executing task, Test...
Build Succeeded
.LINK
Assert
.LINK
Exec
.LINK
FormatTaskName
.LINK
Framework
.LINK
Get-PSakeScriptTasks
.LINK
Include
.LINK
Invoke-psake
.LINK
Properties
.LINK
Task
.LINK
TaskTearDown
#>
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[scriptblock]$setup
)
$psake.context.Peek().taskSetupScriptBlock = $setup
}