Skip to content

Hook into build events

Build Event Handlers run JavaScript code in response to different events during Netlify’s build-deploy lifecycle.

For example, the onPreBuild event handler runs before the site’s build command. The onPostBuild event handler runs after the site build is complete.

// src/index.ts

integration.addBuildEventHandler("onPreBuild", () => {
  console.log("Hello there.");
});

The following event handlers are currently available:

  • onPreBuild: runs before the build command is executed.
  • onBuild: runs directly after the build command is executed and before Functions bundling.
  • onPostBuild: runs after the build command completes; after onBuild tasks and Functions bundling are executed; and before the deploy stage. Can be used to prevent a build from being deployed.
  • onError: runs when an error occurs in the build or deploy stage, failing the build. Can’t be used to prevent a build from being deployed.
  • onSuccess: runs when the deploy succeeds. Can’t be used to prevent a build from being deployed.
  • onEnd: runs after completion of the deploy stage, regardless of build error or success; is useful for resources cleanup. Can’t be used to prevent a build from being deployed.