Environment variables

Environment variables are pairs of key and value that can be used to customize the build process and store sensitive data such as access details to deployment servers.

Levels

Environment Variables can be defined on 4 levels:

  1. Workspace – available for all projects and pipelines. Configured on the dashboard view.
  2. Project – available for all pipelines in the project. Configured on the project view.
  3. Pipeline – available only for the pipeline in which it was defined. Configured in the Variables tab of the pipeline.
  4. Action – available only for the action in which it was defined. Configured in the Variables tab of the action.
Each subsequent tier will overwrite the value from the higher tier. For example, if you have two the same variables, but one is defined on the workspace level and another on the pipeline level, Buddy will use the pipeline value in that pipeline, and the workspace value in the rest of the workspace.

Configuration

When adding a new variable, the following fields are available:

  • Scope – defines the level of the variable
  • Name – the name of the variable, e.g. $SFTP
  • Value – the value conveyed by the name, e.g. 192.168.0.100

Additional options let you hide the value of the variable in the logs, and mark the variable as settable, allowing you to change its value and pass it to the next action or pipeline run.

Example usage

Let's configure some variables to encrypt access to an SFTP server:

  1. Go to the Variables tab in your deployment pipeline.
  2. Add the variables and set your server credentials as values. For example:

    • $SFTP_HOST / 192.168.0.104
    • $SFTP_LOGIN / admin
    • $SFTP_PASS / buddy1234

Variables in pipelineVariables in pipeline

  1. Now you can use the variables to store access credentials to your deployment server:

Storing credentials with variablesStoring credentials with variables

Supported fields

To check if the input supports ENV VARs, click it and see if the dollar icon appears:

Variable icon in action inputVariable icon in action input

Some fields are HTML textareas and do not support variable suggestions – for example, message fields in notifications. They do support ENV VARs perfectly fine, however.
You can also use multi-line environment variables if required.

Default environment variables

Buddy populates a number of environment variables during each pipeline run, for example, the branch from which you deploy, and the ID of the pipeline run. You can use them in webhooks, notifications, conditional runs, and any place that require passing CI/CD-related information.

NameType & Example
BUDDY
Represents whether the current environment is a Buddy environment
Type: Boolean
Example: true
BUDDY_EXECUTION_APPROVE_URL
The URL to the approve/decline prompt of the pipeline waiting for approval
Type: String
Example: https://app.buddy.works/workspace/project/pipelines/pipeline/1/execution/5d9dc42c422f5a26?approve=true
BUDDY_EXECUTION_BRANCH
The name of the Git branch of the current pipeline run
Type: String
Example: master
BUDDY_EXECUTION_CHANGELOG
The list of commits pushed since the last run revision (one commit per line)
Type: List
Example: [e5e13f8] Create buddy.yml | mikebenson | 2024-01-01T07:14:58
BUDDY_EXECUTION_CHANGELOG_ADDED
The list of files added since the last run revision (comma-separated)
Type: List
Example: index.html,main.css
BUDDY_EXECUTION_CHANGELOG_CHANGED
The list of files changed since the last run revision (comma-separated)
Type: List
Example: index.html,main.css
BUDDY_EXECUTION_CHANGELOG_DELETED
The list of files deleted since the last run revision (comma-separated)
Type: List
Example: index.html,main.css
BUDDY_EXECUTION_CLEAR_CACHE
Represents whether the cache was purged before the current pipeline run
Type: Boolean
Example: false
BUDDY_EXECUTION_COMMENT
The comment attached to the current pipeline run
Type: String
Example: my first execution
BUDDY_EXECUTION_EVENT_TYPE
The type of event that triggered the executed pipeline
Type: String
Example: GIT_CREATE
BUDDY_EXECUTION_HASH
The hash of the current pipeline run
Type: String
Example: 5d9dc42c422f5a268b389d08
BUDDY_EXECUTION_ID
The ID of the current pipeline run
Type: Integer
Example: 1
BUDDY_EXECUTION_MODE
The trigger mode used to run the current pipeline run
Type: String
Example: CLICK / EVENT / SCHEDULE
BUDDY_EXECUTION_PARALLEL_SLOT_NO
The slot number of the current execution
Type: Integer
Example: 1
BUDDY_EXECUTION_PREVIOUS_REVISION
The SHA1 hash of the commit of the previous pipeline run
Type: String
Example: e5e13f8b7f8d5c6096a0501dc09b48eef5fea96
BUDDY_EXECUTION_PREVIOUS_REVISION_MESSAGE
The commit message of the previously run revision
Type: String
Example: it is great to code it
BUDDY_EXECUTION_PREVIOUS_REVISION_SUBJECT
The commit subject of the previously run revision
Type: String
Example: New awesome feature
BUDDY_EXECUTION_PULL_REQUEST_BASE_BRANCH
The name of the Git BASE branch of the currently run Pull Request
Type: String
Example: master
BUDDY_EXECUTION_PULL_REQUEST_HEAD_BRANCH
The name of the Git HEAD branch of the currently run Pull Request
Type: String
Example: feature1
BUDDY_EXECUTION_PULL_REQUEST_ID
The ID of the currently run pull request
Type: String
Example: pull/1
BUDDY_EXECUTION_PULL_REQUEST_NO
The number of the currently run pull request
Type: Integer
Example: 1
BUDDY_EXECUTION_REF
The branch/tag/pull request or a wildcard string that was used in the pipeline run
Type: String
Example: refs/tags/v1
BUDDY_EXECUTION_REFRESH
Represents whether the files were uploaded from scratch by the deployment actions in the current pipeline run
Type: Boolean
Example: false
BUDDY_EXECUTION_REVISION
The SHA1 hash of the commit of the current pipeline run
Type: String
Example: 46c360492d6372e5335300776806af412755871
BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL
The email address of the committer email of the currently run revision
Type: String
Example: mike.benson@buddy.works
BUDDY_EXECUTION_REVISION_COMMITTER_NAME
The email address of the committer of the currently run revision
Type: String
Example: Mike Benson
BUDDY_EXECUTION_REVISION_MESSAGE
The commit message of the currently run revision
Type: String
Example: we need to write unit tests!
BUDDY_EXECUTION_REVISION_SHORT
The short hash of the commit of the current pipeline run
Type: String
Example: 46c3604
BUDDY_EXECUTION_REVISION_SUBJECT
The commit subject of the currently run revision
Type: String
Example: Bugfix
BUDDY_EXECUTION_REVISION_URL
The URL of the commit of the current pipeline run
Type: String
Example: https://app.buddy.works/workspace/project/repository/commit/e5e13f8b7f8d5c6096a0501dc09b48eef05fea
BUDDY_EXECUTION_START_DATE
The date of the current pipeline run
Type: String
Example: 2024-01-01T11:27:40.140Z
BUDDY_EXECUTION_TAG
The name of the Git tag of the current pipeline run (provided the run is tagged)
Type: String
Example: v1.0.1
BUDDY_EXECUTION_TIME
The total time of the current pipeline run since the action is triggered (in seconds)
Type: Integer
Example: 69
BUDDY_EXECUTION_URL
The URL of the current pipeline run
Type: String
Example: https://app.buddy.works/my-workspace/my-project/pipelines/pipeline/1/execution/5d9dc42c422f5a268b389
BUDDY_EXECUTION_WARNINGS_COUNT
The total number of warnings that appeared in the current pipeline run
Type: Integer
Example: 3
BUDDY_EXECUTION_WEBHOOK_PAYLOAD
The payload of the webhook that triggered the pipeline
Type: String
Example: { "comment": "my comment", "clearCache": 1 }
BUDDY_FAILED_ACTION_LOGS
The logs from the action that has failed in the current pipeline run (one entry per line)
Type: List
Example: The command '/bin/sh -c test' returned a non-zero code: 127
BUDDY_FAILED_ACTION_NAME
The name of the action that has failed in the current pipeline run
Type: String
Example: Build and test
BUDDY_INVOKER_AVATAR_URL
The URL of the avatar of the pipeline run invoker
Type: String
Example: https://app.buddy.works/image-server/user/0/0/0/0/0/0/1/05d20f3d58ce09a3b4e9g33/w/32/32/AVATAR.png
BUDDY_INVOKER_EMAIL
The email address of the pipeline run invoker
Type: String
Example: mike.benson@buddy.works
BUDDY_INVOKER_ID
The ID of the pipeline run invoker
Type: Integer
Example: 1
BUDDY_INVOKER_NAME
The name of the pipeline run invoker
Type: String
Example: Mike Benson
BUDDY_INVOKER_URL
The URL to the profile of the pipeline run invoker
Type: String
Example: https://app.buddy.works/myworkspace/profile/1
BUDDY_PIPELINE_ID
The ID of the run pipeline
Type: Integer
Example: 1
BUDDY_PIPELINE_NAME
The name of the run pipeline
Type: String
Example: Deploy to Production
BUDDY_PIPELINE_REF_NAME
The branch/tag/pull request or a wildcard string set in the run pipeline
Type: String
Example: refs/tags/v1
BUDDY_PIPELINE_REFS
The list of refs set in the run pipeline
Type: String
Example: refs/heads/branch1,refs/heads/branch2
BUDDY_PIPELINE_TARGET_SITE_URL
The URL of the server to which the pipeline is deploying
Type: String
Example: https://my-server.com
BUDDY_PIPELINE_TRIGGER_MODE
The trigger mode set in the run pipeline
Type: String
Example: CLICK / EVENT / SCHEDULE
BUDDY_PIPELINE_URL
The URL of the run pipeline
Type: String
Example: https://app.buddy.works/my-workspace/my-project/pipelines/pipeline/1
BUDDY_PROJECT_NAME
The name of the project
Type: String
Example: My project
BUDDY_PROJECT_NAME_ID
The ID of the project
Type: Integer
Example: my-project
BUDDY_PROJECT_URL
The URL of the project
Type: String
Example: https://app.buddy.works/workspace/my-project
BUDDY_REPO_SLUG
The slug of the repository
Type: String
Example: githubaccount/repository
BUDDY_REPO_SSH_URL
The SSH URL of the repository
Type: String
Example: git@github.com:githubaccount/repository
BUDDY_SANDBOX_URL
The URL of the created sandbox
Type: String
Example: https://dev-my-project.buddy.cloud
BUDDY_SCM_PROVIDER
The name of the Git hosting provider synchronized with the project
Type: String
Example: GITHUB / BUDDY / BITBUCKET / GITLAB
BUDDY_SCM_URL
The URL of the repository synchronized with the project
Type: String
Example: https://github.com/githubaccount/repository
BUDDY_SIGNED_IPA_PATH
The path in the pipeline filesystem to which the .ipa file is saved
Type: String
Example: export/signedArchive.ipa
BUDDY_WORKERS
The JSON with the information about all installed workers
Type: String
Example: {"workers":[{"name":"Primary","address":"build-server","status":"RUNNING","load":0.56,"free_slots":4,"tag":"NOT_TAGGED","locked":false}],"tags":[{"name":"NOT_TAGGED","avg_load":0.56,"free_slots":4,"workers_quantity":1}]}
BUDDY_WORKERS_ADDRESS_${TAG}
The list of IP addresses of workers tagged with ${TAG}
Type: List
Example: build-server,192.168.1.100
BUDDY_WORKERS_ADDRESS_NOT_TAGGED
The list of IP addresses of untagged workers
Type: List
Example: build-server,192.168.1.100
BUDDY_WORKERS_AVG_LOAD_${TAG}
The average load on all workers tagged with ${TAG}
Type: Float
Example: 0.69
BUDDY_WORKERS_AVG_LOAD_NOT_TAGGED
The average load on all untagged workers
Type: Float
Example: 2.03
BUDDY_WORKERS_CONCURRENT_SLOTS
The total number of concurrent slots across all workers
Type: Integer
Example: 4
BUDDY_WORKERS_COUNT_${TAG}
The number of workers tagged with ${TAG}
Type: Integer
Example: 1
BUDDY_WORKERS_COUNT_NOT_TAGGED
The number of untagged workers
Type: Integer
Example: 1
BUDDY_WORKERS_FREE_SLOTS_NOT_TAGGED
The number of free slots on all untagged workers
Type: Integer
Example: 4
BUDDY_WORKERS_FREESLOTS_${TAG}
The number of free slots on workers tagged with ${TAG}
Type: Integer
Example: 4
BUDDY_WORKSPACE_DOMAIN
The slug of the workspace
Type: String
Example: my-workspace
BUDDY_WORKSPACE_ID
The ID of the workspace
Type: Integer
Example: 1
BUDDY_WORKSPACE_NAME
The name of the workspace
Type: String
Example: My workspace
BUDDY_WORKSPACE_URL
The URL of the workspace
Type: String
Example: https://app.buddy.works/my-workspace
CI
Represents whether the current environment is a non-Buddy CI environment
Type: Boolean
Example: true

Combining into phrases

Variables can be combined with other words to create longer phrases than can be used, for example, to automatically name your infrastructure, releases, or sandboxes. However, you need to obey the following rules:

  • Before the variable: any character is allowed.
  • After the variable: letters, numbers, and footers (_) are not allowed.

Correct usage:

release-$BUDDY_EXECUTION_ID-staging
release$BUDDY_EXECUTION_ID:staging
release_$BUDDY_EXECUTION_ID[staging]

Incorrect usage:

release-$BUDDY_EXECUTION_ID_staging (footer)
release-$BUDDY_EXECUTION_IDstaging (letter)
release-$BUDDY_EXECUTION_ID1staging (number)

Passing variables

Actions

Below you can see a pipeline that saves action logs to a variable and sends it in a notification.

  1. The first action builds the application and saves the log output to logs.txt:

Primary action (always run)Primary action (always run)

  1. In case the build fails, the Local Shell action assigns the content of logs.txt to a variable using export LOGS=$(cat log.txt). The logs are then sent to a Slack channel with $LOGS as the message content:

Conditional actions (run on failure only)Conditional actions (run on failure only)

Make sure to set the variable to Settable, otherwise it will not be possible to change its value.

Pipeline runs

You can pass the values of variables between pipeline runs as well. The values can be saved in one run and then used in another one, e.g. you can set a variable with the version type and increment it in every run.

Pipelines

You can pass a variable between pipelines using the Trigger pipeline action:

  1. Go into the Variables tab in the action details.
  2. Define the name of the variable and the value to pass:

Variables tabVariables tab

You can assign any variable from the target pipeline as the value.

Resetting

To reset settable variables between pipeline runs, you can add an action with a command that will clear the value of the variable (preferably at the beginning or at the end of the pipeline):

export mySettableEnv=$

Reset variable commandReset variable command

On pipeline start

You can parameterize your run using the Pass arguments action. It will pause the pipeline and wait for your input to proceed:

Pass arguments windowPass arguments window

Last modified on December 1, 2023

Questions?

Not sure how to configure a pipeline for your process? Reach out on the live-chat or contact support

Get Started

Sign up for free and deploy your project in less than 10 minutes.