Stacktape

Sign up for freeSign up



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:

  1. Inline information about the script/command into hook
  2. Define named script and reference it in the hook

During execution the script will additionally get the following environment variables:

  • STP_HOOK_TYPE - before or after
  • 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.

executeNamedScript
Required
skipOnCI
skipOnLocal

Copy

scripts:
buildWeb:
executeCommand: npx gatsby build
hooks:
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).

Need help? Ask a question on SlackDiscord or info@stacktape.com.