DB migrations & custom scripts

In addition to 100+ ready-to-use actions, Buddy supports scripts that you can run either as a part of the build, or directly on the server. For example, once the deployment has finished, you can connect to the server, migrate databases and restart the application:

Image loading...Example workflow with SSH script

SSH commands

The SSH action is used to run scripts on any type of Linux server before, during, or after the deployment. In addition to the example above, popular use cases include pulling changes from a Git repository, performing backups, and running PHP Composer on the server.

You can define multiple lines of commands that altogether will be run as a single script. Configuration is similar to the SFTP action and requires providing server details, authorization data, and the commands to run:

Image loading...Example workflow with SSH script

Execution mode 1: Run as script

This is the default running mode. You can choose between SH or BASH-specific syntax, and use Buddy variables and parameters in the commands and URLs.

Execution mode 2: Line by line

Warning
This mode is not recommended and should only be used if Base64 is not installed on the server.

Upon selecting this mode, the commands will be run in non-interactive mode. This means that:

  • Each line is executed in the context of the working directory (default: user’s home dir).
  • Lines are executed from top to bottom.
  • Each command should be one separate line.
  • If a command fails, the next line will not be executed and the action will fail (unless you check ignore errors)- Use absolute paths: the cd command will not be carried to the next line.
  • You can use Buddy specific variables and parameters in commands and URL's.
  • Environment variables between lines are not shared.
  • If you want to use a more complex script, it is advised to call it from the server side (make sure the exit code it returns is correct).

Running repository scripts

If the script that you want to run is located in the repository, you first need to upload it to the server with a deployment action for your type of server. Then, you can execute it over SSH:

Image loading...Uploading script from repository

Build commands

You can also run scripts in Buddy's container actions to compile assets, download dependencies, and run tests before the deployment. All container actions in Buddy come with pre-configured commands depending on the framework and environment. You can add however many commands you need to create complex scripts:

Image loading...Example Node script

Supported environment variables

Buddy populates a number of environment variables during each pipeline run, for example the branch from which you deploy, or the ID of the execution. The full list of default variables is available in the Variables, Keys & Assets tab and in the Buddy variable documentation.

Image loading...List of default variables in Buddy

Last modified on Sep 23, 2024

Recommended