Hooks
Global Hooks
Section titled “Global Hooks”Run before/after any recipe:
@pre echo "=== Starting Jake ==="@post echo "=== Jake Complete ==="Recipe Hooks
Section titled “Recipe Hooks”Run before/after a specific recipe:
task deploy: @pre echo "Pre-deploy checks..." rsync dist/ server:/var/www/ @post echo "Deploy notification sent"Targeted Hooks
Section titled “Targeted Hooks”Target specific recipes without modifying them:
# Run before the "build" recipe only@before build echo "Checking dependencies..."
# Run after the "deploy" recipe only@after deploy notify "Deployment complete"
# Multiple targeted hooks@before test docker-compose up -d@after test docker-compose downError Hooks
Section titled “Error Hooks”Run commands when any recipe fails:
@on_error echo "Recipe failed! Check logs."@on_error notify "Build failed - see logs"Post-hooks Always Run
Section titled “Post-hooks Always Run”Post-hooks run even if the recipe fails, making them ideal for cleanup:
task test: @pre docker-compose up -d npm test @post docker-compose downExecution Order
Section titled “Execution Order”- Global
@prehooks @beforehooks targeting this recipe- Recipe
@prehooks (inside recipe) - Recipe commands
- Recipe
@posthooks (inside recipe) @afterhooks targeting this recipe- Global
@posthooks @on_errorhooks (only if recipe failed)