Knowledge

How to use SSH scripts?

The SSH action allows you to run SSH commands and scripts on your servers. For example, you can add a script that will minify JS files and restart your application after a deployment is made.

Here's how:

  1. Go to Pipelines and select open the target pipeline
  2. Click Manage actions in the right column
  3. Click Add another action and select SSH.
  4. Type in the commands that you want to run on your server, eg:
  5. Select authentication mode and fill in the server details

    gulp uglify
    forever start app.js
    

Click More options to configure additional details, including:

  • Working directory - where you want to execute the commands
  • Action on command failure - you can either stop execution or ignore the error and continue
SSH action
SSH action

What you need to know about SSH commands:

  • 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 in commands and URL's
  • 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).


What parameters you can use in Buddy:

You can use these parameters in the SSH command line:

${workspace.html_url}
${workspace.name}
${workspace.domain}
${invoker.name}
${invoker.email}
${project.html_url}
${project.name}
${project.display_name}
${project.repository_type}
${execution.id}
${execution.html_url}
${execution.start_date}
${execution.mode}
${execution.refresh}
${execution.status}
${execution.comment}
${execution.pipeline.html_url}
${execution.pipeline.name}

You can find the full list of parameters here.

You can fetch more variables from the execution object using:

${execution.action_executions.get(0).status}

Here's an example execution object:

{
    "workspace": {
        "url": "https://app.buddy.works/workspaces/buddy-works",
        "html_url": "https://app.buddy.works/buddy-works",
        "id": 1,
        "name": "Buddy",
        "domain": "buddy.works"
    },
    "invoker": {
        "id": 1,
        "avatar_url": "https://app.buddy.works/buddy-works/image-server/user/0/0/0/0/0/0/1/d643744fbe5ebf2906a4d075a5b97110/w/30/30/CHUCK.png?ts=1432213093596",
        "email": "mike@buddy.works",
        "name": "Mike Benson"
    },
    "project": {
        "url": "https://app.buddy.works/projects/roundkick-v2",
        "html_url": "https://app.buddy.works/beta/roundkick-v2",
        "name": "roundkick-v2",
        "display_name": "Roundkick v2.0"
    },
    "current_date": "2015-08-17T10:45:20.044Z",
    "execution": {
      "url": "https://api.buddy.works/workspaces/buddy/projects/company-website/pipelines/2/executions/3",
      "html_url": "https://app.buddy.works/buddy/company-website/pipelines/pipeline/2/execution/56fa37f499f1e10c105fb388",
      "id": 3,
      "start_date": "2016-03-29T08:08:20.205Z",
      "finish_date": null,
      "mode": "MANUAL",
      "refresh": false,
      "status": "INPROGRESS",
      "comment": "hotfix",
      "branch": {
        "url": "https://api.buddy.works/workspaces/buddy/projects/company-website/repository/branches/master",
        "html_url": "https://app.buddy.works/buddy/company-website/repository/branch/master",
        "name": "master",
        "default": true
      },
      "from_revision": {
        "url": "https://api.buddy.works/workspaces/buddy/projects/company-website/repository/commits/506a3963507943d6908154f4bc9646e829128a08",
        "html_url": "https://app.buddy.works/buddy/company-website/repository/commit/506a3963507943d6908154f4bc9646e829128a08",
        "revision": "506a3963507943d6908154f4bc9646e829128a08",
        "message": "init repo\n"
      },
      "to_revision": {
        "url": "https://api.buddy.works/workspaces/buddy/projects/company-website/repository/commits/506a3963507943d6908154f4bc9646e829128a08",
        "html_url": "https://app.buddy.works/buddy/company-website/repository/commit/506a3963507943d6908154f4bc9646e829128a08",
        "revision": "506a3963507943d6908154f4bc9646e829128a08",
        "message": "init repo\n"
        }
      },
      "creator": {
        "url": "https://api.buddy.works/workspaces/buddy/member/1",
        "html_url": "https://app.buddy.works/buddy/profile/1",
        "id": 1,
        "name": "Mike Benson",
        "avatar_url": "https://app.buddy.works/image-server/user/0/0/0/0/0/0/1/d643744fbe5ebf2906a4d075a5b97110/w/32/32/AVATAR.png",
        "title": "Creative director",
        "email": "mike@buddy.works"
      },
      "pipeline": {
        "url": "https://api.buddy.works/workspaces/buddy/projects/company-website/pipelines/2",
        "html_url": "https://app.buddy.works/buddy/company-website/pipelines/pipeline/2",
        "id": 2,
        "name": "dev",
        "trigger_mode": "MANUAL",
        "ref_name": "master",
        "last_execution_status": "INPROGRESS",
        "last_execution_revision": "506a3963507943d6908154f4bc9646e829128a08"
      },
      "action_executions": [
        {
          "status": "INPROGRESS",
          "progress": 0.0,
          "action": {
            "url": "https://api.buddy.works/workspaces/buddy/projects/company-website/pipelines/2/actions/5",
            "html_url": "https://app.buddy.works/buddy/company-website/pipelines/action/5/edit",
            "id": 5,
            "name": "Upload files to dev",
            "type": "FTP",
            "trigger_time": "ON_EVERY_EXECUTION",
            "last_execution_status": "INPROGRESS",
            "run_only_on_first_failure": false
          }
        }
      ]
}

Get started now

14 days of unlimited trial. No credit card required.