Knowledge

How to use environment variables?

Environment variables are pairs of key-and-value that can be used in Buddy pipelines instead of manually updating the same values across the system on every change. They are most commonly used for authentication credentials, allowing developers to save time looking up and entering access details and eliminating the risk of providing sensitive details in their scripts.

Use Cases

Defining Workspace, Project & Pipeline Variables

You can define your own Environment Variables on 3 levels:

  1. Workspace (available from DashboardPreferences)
  2. Project (available from Project options)
  3. Pipeline (available from pipeline overview)

Each subsequent tier will overwrite the values from the previous tier.

Workspace environment variables

Example Usage

Let’s use the variables to encrypt access to an FTP server:

  1. Go to your deployment pipeline and click the Variables tab
  2. Add variables with the corresponding values. For example:

    • Hostname: FTP_HOST / 192.168.0.100
    • Login: FTP_LOGIN / admin
    • Password: FTP_PASS / buddy1234
Always choose strong passwords for your credentials. You can also encrypt values so they won’t be presented in plain text.

</blockquote>

<!-- -->

<blockquote class="tip">
If you use SSH, you can [**store your keys as variables**](deployments/how-use-ssh-keys-in-actions), too. 

</blockquote>

<figure><img src="https://buddy.works/help/images/deployments/env-vars/how-use-environment-variables-2.png" /><figcaption>Configuring environment variables</figcaption></figure>
  1. Go back to your pipeline and click the upload action
  2. Enter the variables in the corresponding inputs in the following format: ${VARIABLE}:

    • Hostnmame: ${FTP_HOST}
    • Login: ${FTP_LOGIN}
    • Password: ${FTP_PASS}

    TIP: Buddy will automatically suggest the variables once you start typing.

    Using variables in action
  3. Click Test connection to see if everything’s been configured correctly and save the action.

Default 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.

Supported Fields

Here you can check which fields support environment variables:

Action Field
FTP/FTPS Host
  Port
  User
  Pass
  Source Path
  Remote Path
SFTP/Rsync Host
  Port
  User
  Pass
  Passphrase
  Source Path
  Remote Path
  SSH Key (N/A in Rsync)
SSH Commands
  Host
  Port
  User
  Pass
  Passphrase
  Working Dir
HTTP Request URL
  Port
  User
  Pass
  Payload
  Headers
Build Docker Image Login
  Password
  Registry
  Repository
  Version
  Build args
Cloudflare Base URL
Custom Build Commands
  Packages
Rackspace Source Path
  Remote Path
DigitalOcean User
  Pass
  URL
  Source Path
  Remote Path
Amazon S3 BucketID
  Source Path
  Remote Path
Elastic Beanstalk VersionLabel
  Source Path
CodeDeploy Source Path
  Remote Path
AWS CLI Run commands
Lambda ClientContext
  Payload
  Qualifier
Lambda Deploy Source Path
Cloudfront Path
Google Cloud Storage User
  Pass
  URL
  Source Path
  Remote Path
Google Compute Engine User
  Pass
  URL
  Source Path
  Remote Path
Google App Engine Source Path
  Bucket
  Version
  Image URL
WebDAV User
  Pass
  URL
  Source Path
  Remote Path
Git Push URL
  User
  Pass
Slack Message
  Attachments
SMS Content
Email Title
  Content
Pushbullet Title
  Content
  Link
Pushover Title
  Content
  Link
Monitoring Actions Destination
  Port
  User
  Pass
  Send
  Expect
K8s/GKE Authorization (General) Host
  Port
  User
  Password
  API token
  Certificate
Set K8s/GKE Image Image name
  Image tag
Run K8s/GKE Job Image name
  Image tag
  CMD
Apply K8s/GKE Deployment Config file
Trigger pipeline Comment
Heroku CLI Run commands
ZIP Source path
  Target path
  Target file
Newrelic Description
  Changelog
Rollbar Environment
  Comment
  Username
  Rollbar Username
Sentry Release version
  Deploy environment
  Release url
  Deploy url
Datadog Event title
  Content
  Host
  Tags
  Aggregation key
Sign APK APK
  Keystore path
  Keystore pass
  Key password
  Key alias
  Output directory
  Output APK name
Google Play APK path
  Main expansion
  Patch expansion
  Package name
  Mapping file
  Changelog
  Service account key

Get started now

14 days of unlimited trial. No credit card required.