< Back

TaskTearDown

Sun Jan 19, 2020 5:58 pm

NAME TaskTearDown



SYNOPSIS

Adds a scriptblock to the build that will be executed after each task





SYNTAX

TaskTearDown [-teardown] <ScriptBlock> [<CommonParameters>]





DESCRIPTION

This function will accept a scriptblock that will be executed after each task in the build script.



The scriptblock accepts an optional parameter which describes the Task being torn down.





PARAMETERS

-teardown <ScriptBlock>

A scriptblock to execute



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>A sample build script is shown below:



Task default -depends Test



Task Test -depends Compile, Clean {

}



Task Compile -depends Clean {

}



Task Clean {

}



TaskTearDown {

"Running 'TaskTearDown' for task $context.Peek().currentTaskName"

}



The script above produces the following output:



Executing task, Clean...

Running 'TaskTearDown' for task Clean

Executing task, Compile...

Running 'TaskTearDown' for task Compile

Executing task, Test...

Running 'TaskTearDown' for task Test



Build Succeeded









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>A sample build script demonstrating access to the task context is shown below:



Task default -depends Test



Task Test -depends Compile, Clean {

}



Task Compile -depends Clean {

}



Task Clean {

}



TaskTearDown {

param($task)



if ($task.Success) {

"Running 'TaskTearDown' for task $($task.Name) - success!"

} else {

"Running 'TaskTearDown' for task $($task.Name) - failed: $($task.ErrorMessage)"

}

}



The script above produces the following output:



Executing task, Clean...

Running 'TaskTearDown' for task Clean - success!

Executing task, Compile...

Running 'TaskTearDown' for task Compile - success!

Executing task, Test...

Running 'TaskTearDown' for task Test - success!



Build Succeeded











RELATED LINKS

Assert

Exec

FormatTaskName

Framework

Get-PSakeScriptTasks

Include

Invoke-psake

Properties

Task

TaskSetup