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:
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:
The action requires Base64 on the server. If you don't have Base64 installed, you can turn off the option
Run as script at the bottom of the command box. In this case, each line will be executed in a separate session.
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 URL's.
Mode 2: Line by line
If you switch the mode off, the commands will be executed 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 need to upload it to the server first. Just select the deployment action for your type of server, and execute it over SSH:
You can also run scripts before the deployment directly on Buddy's servers using build actions: compile assets, download dependencies, run tests, and so on. All build 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:
Supported Environment Variables
Buddy populates a number of environment variables during each execution, for example the branch from which you deploy and the ID of the execution. Here is the list of populated variables: