-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathHelp.ps1
1355 lines (1091 loc) · 35.6 KB
/
Help.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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
.Synopsis
Help script (https://github.com/nightroman/Helps)
#>
### Invoke-Build.ps1
@{
command = 'Invoke-Build.ps1'
synopsis = 'Invoke-Build - Build Automation in PowerShell'
description = @'
The command invokes so called tasks defined in a PowerShell script.
Let's call this process build and a script with tasks build script.
A build script defines parameters, variables, and one or more tasks.
Any code is invoked with the current location set to $BuildRoot,
the script directory. $ErrorActionPreference is set to 'Stop'.
SCRIPT PARAMETERS
Build scripts define parameters as usual using the param() block.
On calling, specify them for Invoke-Build as if they are its own.
Known issue #4. Specify script switches after Task and File.
The following parameter names are reserved for the engine:
Task, File, Result, Safe, Summary, WhatIf
COMMANDS AND HELP
The following commands are available for build scripts:
task (Add-BuildTask)
exec (Invoke-BuildExec)
assert (Assert-Build)
equals (Assert-BuildEquals)
remove (Remove-BuildItem)
property (Get-BuildProperty)
requires (Test-BuildAsset)
use (Use-BuildAlias)
Confirm-Build
Get-BuildError
Get-BuildSynopsis
Resolve-MSBuild
Set-BuildFooter
Set-BuildHeader
Use-BuildEnv
Write-Build
Write-Warning [1]
[1] Write-Warning is redefined internally in order to count warnings in
a build script and nested scripts. Warnings in modules are not counted.
To get commands help, dot-source Invoke-Build and then call help:
PS> . Invoke-Build
PS> help task -full
SPECIAL ALIASES
Invoke-Build
Build-Parallel
These aliases are for the scripts Invoke-Build.ps1 and Build-Parallel.ps1.
Use them for calling nested builds, i.e. omit script extensions and paths.
PUBLIC VARIABLES
$OriginalLocation - where the build is invoked
$WhatIf - WhatIf mode, Invoke-Build parameter
$BuildRoot - build script location, by default
$BuildFile - build script path
$BuildTask - initial tasks
$Task - current task
$Job - current job
$BuildRoot may be changed by scripts on loading in order to set a custom
build root directory. Other variables should not be changed.
$Task is available for script blocks defined by task parameters If, Inputs,
Outputs, and Jobs and by blocks Enter|Exit-BuildTask, Enter|Exit-BuildJob,
Set-BuildHeader, Set-BuildFooter.
$Task properties:
- Name - [string], task name
- Jobs - [object[]], task jobs
- Started - [DateTime], task start time
And in Exit-BuildTask:
- Error - task error or null
- Elapsed - [TimeSpan], task duration
$Task is also defined in the script scope. It has the only property Name
which is set to $BuildFile, the build script path.
BUILD BLOCKS
Scripts may define special script blocks. They are invoked:
Enter-Build {} - before the first task
Exit-Build {} - after the last task
Enter-BuildTask {} - before each task
Exit-BuildTask {} - after each task
Enter-BuildJob {} - before each task action
Exit-BuildJob {} - after each task action
Set-BuildHeader {param($Path)} - to write task headers
Set-BuildFooter {param($Path)} - to write task footers
Blocks are not called on WhatIf.
Nested builds do not inherit parent blocks.
If Enter-X is called then Exit-X is also called, even on failures.
Enter-Build and Exit-Build are invoked in the script scope. Enter-Build is
suitable for initialization and it can output text unlike the build script.
Enter-BuildTask, Exit-BuildTask, Enter-BuildJob, and Exit-BuildJob are
invoked in the same scope, the parent of task action blocks.
PRIVATE STUFF
Function and variable names starting with '*' are reserved for the engine.
'@
parameters = @{
Task = @'
One or more tasks to be invoked. If it is not specified, null, empty,
or equal to '.' then the task '.' is invoked if it exists, otherwise
the first added task is invoked.
Names with wildcard characters are reserved for special cases.
SAFE REFERENCES
If a task 'X' is referenced as '?X' then it is allowed to fail without
breaking the build, i.e. other tasks specified after X will be invoked.
SPECIAL TASKS
? - Tells to list tasks with brief information and check for errors.
Task synopses are defined in preceding comments as
# Synopsis: ...
or
<#
.Synopsis
...
#>
?? - Tells to collect and get all tasks as an ordered dictionary.
It can be used by external tools for analysis, completion, etc.
Tasks ? and ?? set $WhatIf to true. Properly designed build scripts
should not perform anything significant if $WhatIf is set to true.
* - Tells to invoke all tasks, for example when tasks are tests.
** - Invokes * for all files *.test.ps1 found recursively in the
current directory or a directory specified by the parameter File.
'@
File = @'
The script which adds tasks using the command 'task' (Add-BuildTask).
If File is omitted then Invoke-Build looks for *.build.ps1 files in the
current location and takes the first in Sort-Object order.
If the file is not found then a command set by the environment variable
InvokeBuildGetFile is invoked with the directory path as an argument.
This command may return the full path of a special build script.
If the file is still not found then parent directories are searched.
DIRECTORY PATH
File accepts directory paths as well. The build script is resolved as
described above for the specified directory without searching parents.
INLINE SCRIPT
File also accepts script blocks. In this case $BuildFile is the calling
script, if any, or null. The default $BuildRoot is $BuildFile directory
or the current location.
Script parameters, parallel, and persistent builds are not supported.
'@
Result = @'
Tells to make the build result. Normally it is the name of a variable
created in the calling scope. Or it is a hashtable which entry Value
contains the result.
Result properties:
All - all available tasks
Error - a terminating build error
Tasks - invoked tasks including nested
Errors - error objects including nested
Warnings - warning objects including nested
Redefined - list of original redefined tasks
Tasks is a list of objects:
Name - task name
Jobs - task jobs
Error - task error
Started - start time
Elapsed - task duration
InvocationInfo - task location (.ScriptName, .ScriptLineNumber)
Errors is a list of objects:
Error - original error
File - current $BuildFile
Task - current $Task or null for other errors
Warnings is a list of objects:
Message - warning message
File - current $BuildFile
Task - current $Task or null for other warnings
Do not change these data and do not use not documented members.
'@
Safe = @'
Tells to catch a build failure, store an error as the property Error of
Result and return quietly. A caller should use Result and check Error.
Some exceptions are possible even in the safe mode. They show serious
errors, not build failures. For example, a build script is missing.
When Safe is used together with the special task ** (invoke *.test.ps1)
then task failures stop current test scripts, not the whole testing.
'@
Summary = @'
Tells to show summary information after the build. It includes task
durations, names, locations, and error messages.
'@
WhatIf = @'
Tells to show tasks and jobs to be invoked and some analysis of used
parameters and environment variables. See Show-TaskHelp for details.
If a script does anything but adding tasks then it should check for
$WhatIf and skip the real actions in order to support WhatIf calls.
Alternatively, use the Enter-Build block for pre-build actions.
'@
}
outputs = @(
@{
type = 'Text'
description = @'
Build log which includes task records and engine messages, warnings,
errors, and output from build script tasks and special blocks.
The script itself should not output anything. Unexpected script output
causes warnings, in the future it may be treated as an error.
'@
}
)
examples = @(
@{code={
## How to call Invoke-Build in order to deal with build failures.
## Use one of the below techniques or you may miss some failures.
## (1/2) If you do not want to catch errors and just want the calling
## script to stop on build failures then
$ErrorActionPreference = 'Stop'
Invoke-Build ...
## (2/2) If you want to catch build errors and proceed further depending
## on them then use try/catch, $ErrorActionPreference does not matter:
try {
Invoke-Build ...
# Build completed
}
catch {
# Build FAILED, $_ is the error
}
}}
@{code={
# Invoke tasks Build and Test from the default script with parameters.
# The script defines parameters Output and WarningLevel by param().
Invoke-Build Build, Test -Output log.txt -WarningLevel 4
}}
@{code={
# Show tasks in the default script and the specified script
Invoke-Build ?
Invoke-Build ? Project.build.ps1
# Custom formatting is possible, too
Invoke-Build ? | Format-Table -AutoSize
Invoke-Build ? | Format-List Name, Synopsis
}}
@{code={
# Get task names without invoking for listing, TabExpansion, etc.
$all = Invoke-Build ??
$all.Keys
}}
@{code={
# Invoke all in Test1.test.ps1 and all in Tests\...\*.test.ps1
Invoke-Build * Test1.test.ps1
Invoke-Build ** Tests
}}
@{code={
# How to use build results, e.g. for summary
try {
# Invoke build and get the variable Result
Invoke-Build -Result Result
}
finally {
# Show build error
"Build error: $(if ($Result.Error) {$Result.Error} else {'None'})"
# Show task summary
$Result.Tasks | Format-Table Elapsed, Name, Error -AutoSize
}
}}
)
links = @(
@{ text = 'Wiki'; URI = 'https://github.com/nightroman/Invoke-Build/wiki' }
@{ text = 'Project'; URI = 'https://github.com/nightroman/Invoke-Build' }
# external
@{ text = 'Build-Checkpoint' }
@{ text = 'Build-Parallel' }
# special
@{ text = '' }
@{ text = 'For other commands, at first invoke:' }
@{ text = 'PS> . Invoke-Build' }
@{ text = '' }
# aliases
@{ text = 'task (Add-BuildTask)' }
@{ text = 'exec (Invoke-BuildExec)' }
@{ text = 'assert (Assert-Build)' }
@{ text = 'equals (Assert-BuildEquals)' }
@{ text = 'remove (Remove-BuildItem)' }
@{ text = 'property (Get-BuildProperty)' }
@{ text = 'requires (Test-BuildAsset)' }
@{ text = 'use (Use-BuildAlias)' }
# functions
@{ text = 'Confirm-Build' }
@{ text = 'Get-BuildError' }
@{ text = 'Get-BuildSynopsis' }
@{ text = 'Resolve-MSBuild' }
@{ text = 'Set-BuildFooter' }
@{ text = 'Set-BuildHeader' }
@{ text = 'Write-Build' }
)
}
### Add-BuildTask
@{
command = 'Add-BuildTask'
synopsis = '(task) Defines and adds a task.'
description = @'
Scripts use its alias 'task'. It is normally used in the build script scope
but it can be called from another script or function. Build scripts should
have at least one task.
This command is all that build scripts really need. Tasks are main build
blocks. Other build commands are helpers, scripts do not have to use them.
In addition to task parameters, you may use task help comments, synopses,
preceding task definitions:
# Synopsis: ...
task ...
Synopses are used in task help information returned by the command
Invoke-Build ?
To get a task synopsis during a build, use Get-BuildSynopsis.
'@
parameters = @{
Name = @'
The task name. Wildcard characters are deprecated and "?" must not be
the first character. Duplicated names are allowed, each added task
overrides previously added with the same name.
'@
Jobs = @'
Specifies one or more task jobs or a hashtable with actual parameters.
Jobs are other task references and own actions, script blocks. Any
number of jobs is allowed. Jobs are invoked in the specified order.
Valid jobs are:
[string] - an existing task name, normal reference
[string] "?Name" - safe reference to a task allowed to fail
[scriptblock] - action, a script block invoked for this task
Special value:
[hashtable] which contains the actual task parameters in addition
to the task name. This task definition is more convenient with
complex parameters, often typical for incremental tasks.
Example:
task Name @{
Inputs = {...}
Outputs = {...}
Partial = $true
Jobs = {
process {...}
}
}
'@
After = @'
Tells to add this task to the end of jobs of the specified tasks.
Altered tasks are defined as normal references (TaskName) or safe
references (?TaskName). In the latter case this inserted task may
fail without stopping a build.
Parameters After and Before are used in order to alter task jobs
in special cases when direct changes in task source code are not
suitable. Use Jobs in order to define relations in usual cases.
'@
Before = @'
Tells to insert this task to jobs of the specified tasks.
It is inserted before the first action or added to the end.
See After for details.
'@
If = @{default = '$true'; description = @'
Specifies the optional condition to be evaluated. If the condition
evaluates to false then the task is not invoked. The condition is
defined in one of two ways depending on the requirements.
Using standard Boolean notation (parenthesis) the condition is checked
once when the task is defined. A use case for this notation might be
evaluating a script parameter or another sort of global condition.
Example:
task Task1 -If ($Param1 -eq ...) {...}
task Task2 -If ($PSVersionTable.PSVersion.Major -ge 5) {...}
Using script block notation (curly braces) the condition is evaluated
on task invocation. If a task is referenced by several tasks then the
condition is evaluated each time until it gets true and the task is
invoked. The script block notation is normally used for a condition
that may be defined or changed during the build or just expensive.
Example:
task SomeTask -If {...} {...}
'@}
Inputs = @'
Specifies the input items, tells to process the task as incremental,
and requires the parameter Outputs with the optional switch Partial.
Inputs are file items or paths or a script block which gets them.
Outputs are file paths or a script block which gets them.
A script block is invoked with input paths piped to it.
Automatic variables for incremental task actions:
$Inputs - full input paths, array of strings
$Outputs - result of the evaluated Outputs
With the switch Partial the task is processed as partial incremental.
There must be one-to-one correspondence between Inputs and Outputs.
Partial task actions often contain "process {}" blocks.
Two more automatic variables are available for them:
$_ - full path of an input item
$2 - corresponding output path
See also wiki topics about incremental tasks:
https://github.com/nightroman/Invoke-Build/wiki
'@
Outputs = @'
Specifies the output paths of the incremental task, either directly on
task creation or as a script block invoked with the task. It is used
together with Inputs. See Inputs for details.
'@
Partial = @'
Tells to process the incremental task as partial incremental.
It is used with Inputs and Outputs. See Inputs for details.
'@
Data = @'
Any object attached to the task. It is not used by the engine.
When the task is invoked this object is available as $Task.Data.
'@
Done = @'
Specifies the command or a script block which is invoked after the
task. Custom handlers should check for $Task.Error if it matters.
'@
Source = @'
Specifies the task source. It is used by wrapper functions in order to
provide the actual source for location messages and synopsis comments.
'@
}
examples = @(
### Job combinations
@{
code={
# Dummy task with no jobs
task Task1
# Alias of another task
task Task2 Task1
# Combination of tasks
task Task3 Task1, Task2
# Simple action task
task Task4 {
# action
}
# Typical complex task: referenced task(s) and one own action
task Task5 Task1, Task2, {
# action after referenced tasks
}
# Possible complex task: actions and tasks in any required order
task Task6 {
# action before Task1
},
Task1, {
# action after Task1 and before Task2
},
Task2
}
remarks = @'
This example shows various possible combinations of task jobs.
'@
}
### Splatting helper
@{
code={
# Synopsis: Complex task with parameters as a hashtable.
task TestAndAnalyse @{
If = !$SkipAnalyse
Inputs = {
Get-ChildItem . -Recurse -Include *.ps1, *.psm1
}
Outputs = {
'Analyser.log'
}
Jobs = 'Test', {
Invoke-ScriptAnalyzer . > Analyser.log
}
}
# Synopsis: Simple task with usual parameters.
task Test -If (!$SkipTest) {
Invoke-Pester
}
}
remarks = @'
Tasks with complex parameters are often difficult to compose in a readable
way. In such cases use a hashtable in order to specify task parameters in
addition to the task name. Keys and values correspond to parameter names
and values.
'@
}
)
links = @(
@{ text = 'Get-BuildError' }
@{ text = 'Get-BuildSynopsis' }
@{ URI = 'https://github.com/nightroman/Invoke-Build/wiki' }
)
}
### Get-BuildError
@{
command = 'Get-BuildError'
synopsis = 'Gets the specified task error.'
description = @'
The specified task is usually safe referenced in the build (?name) and a
caller (usually a downstream task) gets its potential error for analysis.
'@
parameters = @{
Task = @'
Name of the task which error is requested.
'@
}
outputs = @(
@{
type = 'Error'
description = 'An error or null if the task has not failed.'
}
)
links = @(
@{ text = 'Add-BuildTask' }
)
}
### Assert-Build
@{
command = 'Assert-Build'
synopsis = '(assert) Checks for a condition.'
description = @'
Scripts use its alias 'assert'. This command checks for a condition and
if it is not true throws an error with the default or specified message.
'@
parameters = @{
Condition = @'
The condition.
'@
Message = @'
An optional message describing the assertion condition.
'@
}
links = @(
@{ text = 'Assert-BuildEquals' }
)
}
### Assert-BuildEquals
@{
command = 'Assert-BuildEquals'
synopsis = '(equals) Verifies that two specified objects are equal.'
description = @'
Scripts use its alias 'equals'. This command verifies that two specified
objects are equal using [Object]::Equals(). If objects are not equal the
command fails with a message showing object values and types.
'@
parameters = @{
A = 'The first object.'
B = 'The second object.'
}
links = @(
@{ text = 'Assert-Build' }
)
}
### Get-BuildProperty
@{
command = 'Get-BuildProperty'
synopsis = '(property) Gets the session or environment variable or the default.'
description = @'
Scripts use its alias 'property'. The command returns:
- session variable value if it is not $null or ''
- environment variable if it is not $null or ''
- default value if it is not $null
- error
'@
parameters = @{
Name = @'
Specifies the session or environment variable name.
'@
Value = @'
Specifies the default value. If it is omitted or null then the variable
must exist with a not empty value. Otherwise an error is thrown.
'@
}
outputs = @(
@{
type = 'Object'
description = 'Requested property value.'
}
)
examples = @(
@{code={
# Inherit an existing value or throw an error
$OutputPath = property OutputPath
}}
@{code={
# Get an existing value or use the default
$WarningLevel = property WarningLevel 4
}}
)
links = @(
@{ text = 'Test-BuildAsset' }
)
}
### Get-BuildSynopsis
@{
command = 'Get-BuildSynopsis'
synopsis = 'Gets the task synopsis.'
description = @'
Gets the specified task synopsis if it is available.
Task synopses are defined in preceding comments as
# Synopsis: ...
or
<#
.Synopsis
...
#>
This function may be used in Set-BuildHeader for printing task synopses.
'@
parameters = @{
Task = @'
The task object. During the build, the current task is available as the
automatic variable $Task.
'@
Hash = @'
A hashtable for caching. Build scripts do not have to specify it, the
internal cache is used by default. It is designed for external tools.
'@
}
outputs = @{
type = 'String'
}
examples = @{code={
# Headers: print task paths as usual and synopses in addition
Set-BuildHeader {
param($Path)
Write-Build Cyan "Task $Path : $(Get-BuildSynopsis $Task)"
}
# Synopsis: This task prints its own synopsis.
task Task1 {
'My synopsis : ' + (Get-BuildSynopsis $Task)
}
}}
links = @(
@{ text = 'Set-BuildFooter' }
@{ text = 'Set-BuildHeader' }
)
}
### Invoke-BuildExec
@{
command = 'Invoke-BuildExec'
synopsis = '(exec) Invokes an application and checks $LastExitCode.'
description = @'
Scripts use its alias 'exec'. It invokes the specified script block which
is supposed to call an executable. Then $LastExitCode is checked. If it
does not fit to the specified values (0 by default) an error is thrown.
If you have any issues with standard error output of the invoked app, try
using `exec` with -ErrorAction Continue, SilentlyContinue, or Ignore. This
does not affect failures of `exec`, they still depend on the app exit code.
But this may work around some known PowerShell issues with standard errors.
'@
parameters = @{
Command = @'
Command that invokes an executable which exit code is checked. It must
invoke an application directly (.exe) or not (.cmd, .bat), otherwise
$LastExitCode is not set and may contain the code of another command.
'@
ExitCode = @{default = '@(0)'; description = @'
Valid exit codes (e.g. 0..3 for robocopy).
'@}
ErrorMessage = @'
Specifies the text included to standard error messages.
'@
Echo = @'
Tells to write the command and its used variable values.
WARNING: With echo you may expose sensitive information.
'@
StdErr = @'
Tells to set $ErrorActionPreference to Continue, capture all output and
write as strings. Then, if the exit code is failure, add the standard
error output text to the error message.
'@
}
outputs = @(
@{
type = 'Objects'
description = @'
Output of the specified command.
'@
}
)
examples = @(
@{code={
# Call robocopy (0..3 are valid exit codes)
exec { robocopy Source Target /mir } (0..3)
}}
)
links = @(
@{ text = 'Use-BuildAlias' }
@{ text = 'Use-BuildEnv' }
)
}
### Remove-BuildItem
@{
command = 'Remove-BuildItem'
synopsis = '(remove) Removes specified items.'
description = @'
Scripts use its alias 'remove'. This command removes existing items,
ignores missing items, and fails if it cannot remove existing items.
Use the switch Verbose in order to output messages about removing
existing and skipping missing items or patterns specified by Path.
'@
parameters = @{
Path = @{
wildcard = $true
description = @'
Specifies the items to be removed. Wildcards are allowed.
The parameter is mostly the same as Path of Remove-Item.
For sanity, paths with only ., *, \, / are not allowed.
'@
}
}
examples = @(
@{code={
# Remove some temporary items
remove bin, obj, *.test.log
}}
)
}
### Set-BuildFooter
@{
command = 'Set-BuildFooter'
synopsis = 'Tells how to write task footers.'
description = @'
This build block is used in order to change the default task footer format.
Use the automatic variable $Task in order to get the current task data.
Use Write-Build in order to write with colors.
'@
parameters = @{
Script = @'
The script like {param($Path) ...} which is used in order to write task
footers. The parameter Path includes the parent and current task names.
In order to omit task footers, set an empty block:
Set-BuildFooter {}
'@
}
examples = @{code={
# Use the usual footer format but change the color
Set-BuildFooter {
param($Path)
Write-Build DarkGray "Done $Path $($Task.Elapsed)"
}
# Synopsis: Data for footers in addition to $Path and $Task.Elapsed
task Task1 {
'Task name : ' + $Task.Name
'Start time : ' + $Task.Started
'Location path : ' + $Task.InvocationInfo.ScriptName
'Location line : ' + $Task.InvocationInfo.ScriptLineNumber
}
}}
links = @(
@{ text = 'Get-BuildSynopsis' }
@{ text = 'Set-BuildHeader' }
@{ text = 'Write-Build' }
)
}
### Set-BuildHeader
@{
command = 'Set-BuildHeader'
synopsis = 'Tells how to write task headers.'
description = @'
This build block is used in order to change the default task header format.
Use the automatic variable $Task in order to get the current task data.
Use Write-Build in order to write with colors.
'@
parameters = @{
Script = @'
The script like {param($Path) ...} which is used in order to write task
headers. The parameter Path includes the parent and current task names.
'@
}
examples = @{code={
# Headers: write task paths as usual and synopses in addition
Set-BuildHeader {
param($Path)
Write-Build Cyan "Task $Path --- $(Get-BuildSynopsis $Task)"
}
# Synopsis: Data for headers in addition to $Path and Get-BuildSynopsis
task Task1 {
'Task name : ' + $Task.Name
'Start time : ' + $Task.Started
'Location path : ' + $Task.InvocationInfo.ScriptName
'Location line : ' + $Task.InvocationInfo.ScriptLineNumber
}
}}
links = @(
@{ text = 'Get-BuildSynopsis' }
@{ text = 'Set-BuildFooter' }
@{ text = 'Write-Build' }
)
}
### Test-BuildAsset
@{
command = 'Test-BuildAsset'
synopsis = '(requires) Checks for required build assets.'
description = @'
Scripts use its alias 'requires'. This command tests the specified assets.
It fails if any is missing. It is used in script code (common assets) and
in tasks (individual assets).
'@
parameters = @{
Variable = @'
Specifies the required session variable names and tells to fail if a
variable is missing or its value is null or empty string.
'@
Environment = @'
Specifies the required environment variable names.
'@
Path = @'
Specifies literal paths to be tested by Test-Path. If the specified
expression uses required assets then test these assets first by a
separate command.
'@
Property = @'
Specifies session or environment variable names and tells to fail if a
variable is missing or its value is null or empty string.
'@
}
links = @(
@{ text = 'Get-BuildProperty' }
)
}
### Use-BuildAlias
@{
command = 'Use-BuildAlias'
synopsis = '(use) Sets framework or directory tool aliases.'
description = @'
Scripts use its alias 'use'. Invoke-Build does not change the system path
in order to make framework tools available by names. This is not suitable
for using mixed framework tools (in different tasks, scripts, parallel
builds). Instead, this function is used for setting tool aliases in the
scope where it is called.