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:
Example workflow with SSH script
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:
Example workflow with SSH script
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:
Uploading script from repository
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:
Example Node. script
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:
BUDDY_WORKSPACE_URL BUDDY_WORKSPACE_ID BUDDY_WORKSPACE_NAME BUDDY_WORKSPACE_DOMAIN BUDDY_PROJECT_URL BUDDY_PROJECT_NAME BUDDY_PROJECT_NAME_ID BUDDY_REPO_SLUG BUDDY_INVOKER_URL BUDDY_INVOKER_ID BUDDY_INVOKER_NAME BUDDY_INVOKER_EMAIL BUDDY_INVOKER_AVATAR_URL BUDDY_EXECUTION_URL BUDDY_EXECUTION_ID BUDDY_EXECUTION_START_DATE BUDDY_EXECUTION_MODE BUDDY_EXECUTION_CLEAR_CACHE BUDDY_EXECUTION_REFRESH BUDDY_EXECUTION_COMMENT BUDDY_EXECUTION_BRANCH BUDDY_EXECUTION_TAG BUDDY_EXECUTION_PULL_REQUEST_ID BUDDY_EXECUTION_PREVIOUS_REVISION BUDDY_EXECUTION_PREVIOUS_REVISION_MESSAGE BUDDY_EXECUTION_REVISION BUDDY_EXECUTION_REVISION_SHORT BUDDY_EXECUTION_REVISION_MESSAGE BUDDY_EXECUTION_REVISION_SUBJECT BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL BUDDY_PIPELINE_URL BUDDY_PIPELINE_ID BUDDY_PIPELINE_NAME BUDDY_PIPELINE_REF_NAME BUDDY_PIPELINE_TRIGGER_MODE BUDDY_PIPELINE_TARGET_SITE_URL BUDDY_FAILED_ACTION_LOGS BUDDY_FAILED_ACTION_NAME BUDDY_EXECUTION_CHANGELOG BUDDY_EXECUTION_PULL_REQUEST_NO BUDDY_EXECUTION_PREVIOUS_REVISION_SUBJECT BUDDY_EXECUTION_REVISION_COMMITTER_NAME
Last modified on April 26, 2022