Skip to content

Deployment hooks

Pre- and post-deploy scripts on Stack Harbor PaaS — when they run, where they fit in the deploy dialog, how to write them, and how to inspect their output.

A deployment hook is a script that runs as part of every deploy on Stack Harbor PaaS — either before the application is deployed or immediately after. Hooks are attached per-deployment from the deploy dialog and execute inside the target container.

For Maven build nodes and the Go application server, hooks can also be attached to the build step in addition to deploy.

Where hooks live

Hooks are configured from the Hooks expandable section in the deploy dialog. The dialog opens from two places:

  • Deployment Manager — hover over an archive or VCS project entry and click Deploy to.
  • Application server — hover over the Deployments row and pick a source (Local file, URL, or Git / SVN).

In the deploy dialog, click Pre or Post to open the editor for the corresponding hook.

Writing a hook

The hook editor accepts code in any language whose interpreter is installed in the target container. Bash is available by default; Python, Node, PHP, and Ruby interpreters are available depending on the runtime of the application server. If you need a specific interpreter that is not in the default stack image, install it via a redeploy with a custom image or via a pre-deploy hook.

The editor toolbar provides:

  • Wrap lines — wraps long lines so the full text remains visible.
  • Search — find within the hook, with optional match-case and regex.
  • Help — opens this reference.

Click Apply to save the hook, then deploy.

Pre-deploy hooks — common uses

The pre-deploy hook runs before the new code reaches the application server. Use it to:

  • Check that prerequisites are met.
  • Pre-install required software (apt-get, yum, pip, npm).
  • Clear or prepare a dedicated folder for application files.
  • Log the start of the deployment.

Post-deploy hooks — common uses

The post-deploy hook runs after the new code is in place. Use it to:

  • Restart the application server.
  • Install project dependencies (npm install, bundle install, composer install).
  • Apply database migrations.
  • Update file permissions or symlinks.
  • Log the end of the deployment.

Inspecting hook output

When a deployment completes, click Show Logs in the dashboard notification to view the action log. Hook stdout and stderr are written to the hooks.log file, accessible through the Logs section on the application server.

If a hook fails, the deployment is aborted and a notification surfaces. Click Show Logs to view the error and adjust the hook before retrying.

Exiting a hook

Use exit 0 from inside a hook to signal success. Any non-zero exit code is treated as failure and aborts the deployment. This lets you fail-fast on a pre-deploy condition check (for example, exit 1 if a required environment variable is missing).

Example: deployment timestamp log

A minimal pair of hooks that records the start and end of each deployment.

Pre-deploy hook:

echo "$(date) - deployment start" >> ~/mylog
if ! grep -q "$(pwd)/mylog" /etc/jelastic/redeploy.conf; then
    echo "$(pwd)/mylog" >> /etc/jelastic/redeploy.conf
fi

The first line appends a timestamped entry to ~/mylog. The conditional ensures mylog is listed in /etc/jelastic/redeploy.conf, so the file survives a container redeploy.

Post-deploy hook:

echo "$(date) - deployment end" >> ~/mylog

After deployment, inspect ~/mylog and /etc/jelastic/redeploy.conf via the file manager or SSH to confirm the hooks ran.

Preserving files written by hooks

Files outside the platform-managed paths are wiped on container redeploy. To keep a file across redeploys, add its full path to the custom files and folders section of /etc/jelastic/redeploy.conf. The redeploy operation then carries the file over.

For data that doesn’t belong in a config file, use a container volume — see the redeploy preserved data reference.

See also