This document covers advanced features available for Trident projects. These features are optional and provide additional customization beyond the standard project workflow.
Build Script Hooks
Build script hooks allow you to execute custom shell scripts before and after the build process.
Overview
The build system supports two types of build hooks:
- Pre-build scripts: Execute before the build starts
- Post-build scripts: Execute after the build completes successfully
Script Files
To use build hooks, create one or both of the following files in your project root directory (file name must match):
| Script File | When It Runs | Build Behavior on Failure |
| tr_prebuild_script.sh | Before build starts | Build is aborted |
| tr_postbuild_script.sh | After successful build | Reported as error, build artifacts remain |
How It Works
Pre-build Scripts
Pre-build scripts run before any build processes begin. They are useful for:
- Validating the build environment
- Generating source code or configuration files
- Checking for required dependencies
- Running linters or static analysis tools
- Verifying project configuration
Important: If a pre-build script fails (exits with a non-zero code), the build is immediately aborted and no build artifacts are created.
Post-build Scripts
Post-build scripts run only after the build completes successfully. They are useful for:
- Copying build artifacts to specific locations
- Generating checksums or signatures
- Running post-build tests
- Creating deployment packages
- Uploading artifacts to a server
- Generating build reports
Important: Post-build scripts only run if the build succeeds. If the build fails, the post-build script is skipped.
Script Requirements
- File Location: Scripts must be in the project root directory
- File Names: Must be exactly tr_prebuild_script.sh or tr_postbuild_script.sh
- Shell: Scripts must be valid bash scripts
- Working Directory: Scripts execute with the project root as the working directory
Build Execution Flow
Here's how the build process works with build hooks:
1. Clean (if --clean flag used)
2. Pre-build script (if tr_prebuild_script.sh exists)
- If fails: Abort, show error, exit with pre-build exit code
3. Build process
- If fails: Skip post-build, exit with build exit code
4. Post-build script (if tr_postbuild_script.sh exists)
- If fails: Show error, exit with post-build exit code
5. Exit 0 (success)
Troubleshooting
Script Not Running
Problem: Script exists but doesn't execute
Solutions:
- Verify the file name is exactly tr_prebuild_script.sh or tr_postbuild_script.sh
- Ensure the script is in the project root (same directory as trident.toml)
- Check that bash is installed and in PATH
- Run with --verbose to see detailed logging