How to Conditionally Run Predeploy Jobs

Last updated: April 3, 2025

While our system doesn't natively support conditional predeploy job execution, you can implement this functionality using environment variables. This approach allows you to control when predeploy jobs, such as database migrations, are run.

Implementation Steps

  1. Set an environment variable to control the predeploy job execution. For example: SKIP_NEXT_PREDEPLOY_RUN=true or SKIP_NEXT_PREDEPLOY_RUN=false

  2. In your predeploy job configuration, add a conditional check for this environment variable. For example:

if [ "$SKIP_NEXT_PREDEPLOY_RUN" != "true" ]; then
  # Run your predeploy job (e.g., database migrations)
else
  echo "Skipping predeploy job"
fi

Use Case Example

This approach is particularly useful when you need flexibility in your deployment process. For instance:

  • For most deployments, you might want to run database migrations as a predeploy job.

  • In some cases, you may prefer to run migrations as a postdeploy job instead.

By setting the SKIP_NEXT_PREDEPLOY_RUN variable appropriately before each deployment, you can control when the predeploy job runs, giving you the flexibility to choose between predeploy and postdeploy migrations as needed.

Remember to reset the environment variable after each deployment if you want subsequent deployments to behave differently.