How to use SSH scripts?
The SSH action allows you to run scripts and commands on your server. For example, you can add a script that will minify JS files and restart your application after the deployment.
Mode 1: Run as script
By default the commands are run in Run as a script mode. You can choose between SH or BASH specific syntax and use Buddy variables and parameters in commands and URLs (see below):
Mode 2: Line by line
If you switch the mode off, the commands will be executed in the 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 URLs
- Environment variables between lines are not shared
If you want to use a more complex script, it its advised to call it from the server side (make sure the exit code it returns is correct).
Supported Environment Variables
Buddy populate 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_MESSAGE BUDDY_EXECUTION_REVISION_COMMITER_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
On top of the default environment variables, you can also use Buddy parameters, e.g. for email notifications on velocity templates.