Hooks
Introduction
- Hooks allow you to execute a custom command or script before or after specified command is executed.
- Example use cases:
- build, validate or lint your application before deployment
- run unit tests on your application before deployment
- execute database migration after deployment
- cleanup database before delete
Usage
When using hooks, you can either:
- Inline information about the script/command into hook
- Define named script and reference it in the hook
During execution the script will additionally get the following environment variables:
STP_HOOK_TYPE
-before
orafter
STP_COMMAND
- Stacktape command used
Using named script
Named scripts can be referenced in a hook, but they can also be executed manually. Refer to scripts docs to learn more.
NamedScriptLifecycleHook API reference
Parent:Hooks
executeNamedScript
Required
skipOnCI
skipOnLocal
Copy
scripts:buildWeb:executeCommand: npx gatsby buildhooks:beforeDeploy:- executeNamedScript: buildWeb
Using named script in the hook
Using inline script
By inlining script you can provide all information directly in the hook.
InlineScriptLifecycleHook API reference
Parent:Hooks
executeScript
executeCommand
executeScripts
executeCommands
environment
bastionTunnels
cwd
pipeStdio
Default: true
skipOnCI
skipOnLocal
Copy
hooks:beforeDeploy:- executeCommand: npx gatsby build
Using inlined script
Hookable events
Hooks API reference
beforeDeploy
afterDeploy
beforeDelete
afterDelete
beforeBucketSync
afterBucketSync
beforeDev
afterDev
Before command hooks
- Executed before the command, but AFTER the configuration has been successfully loaded.
Executed only if the configuration was successfully loaded and hooks have been registered. The hook won't be executed if there's an error with your CLI arguments or in your configuration.
After command hooks
- Executed after the command has successfully finished.
- For convenience,
afterDeploy
hook can reference parameters of your stack resources in its environment variables (using $ResourceParam() and $CfResourceParam() directives).