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:
- Workspace – available for all projects and pipelines. Configured on the dashboard view.
- Project – available for all pipelines in the project. Configured on the project view.
- Pipeline – available only for the pipeline in which it was defined. Configured in the Variables tab of the pipeline.
- 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:
- Go to the Variables tab in your deployment pipeline.
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 pipeline
- Now you can use the variables to store access credentials to your deployment server:
Storing 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 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.
Name | Value |
---|---|
BUDDY Represents whether the current environment is a Buddy environment | true |
BUDDY_EXECUTION_APPROVE_URL The URL to the approve/decline prompt of the pipeline waiting for approval | https://app.buddy.works/myworkspace/my-project/pipelines/pipeline/1/execution/63f0047edcsdd4c461a0000f0?approve=true |
BUDDY_EXECUTION_BRANCH The name of the Git branch of the current pipeline run | master |
BUDDY_EXECUTION_CLEAR_CACHE Represents whether the cache was purged before the current pipeline run | false |
BUDDY_EXECUTION_CHANGELOG The list of commits pushed since the last run revision (one commit per line) | [e5e13f8] Create buddy.yml | mikebenson | 2019-01-01T07:14:58 |
BUDDY_EXECUTION_CHANGELOG_ADDED The list of files added since the last run revision (comma-separated) | index.html,main.css |
BUDDY_EXECUTION_CHANGELOG_CHANGED The list of files changed since the last run revision (comma-separated) | index.html,main.css |
BUDDY_EXECUTION_CHANGELOG_DELETED The list of files deleted since the last run revision (comma-separated) | index.html,main.css |
BUDDY_EXECUTION_COMMENT The comment attached to the current pipeline run | My first pipeline run |
BUDDY_EXECUTION_EVENT_TYPE The type of event that triggered the executed pipeline | GIT_CREATE |
BUDDY_EXECUTION_ID The ID of the current pipeline run | 1 |
BUDDY_EXECUTION_MODE The trigger mode used to run the current pipeline run | CLICK |
BUDDY_EXECUTION_PARALLEL_SLOT_NO The slot number of the current execution | 1 |
BUDDY_EXECUTION_PREVIOUS_REVISION The SHA1 hash of the commit of the previous pipeline run | 5631d80000a6a17a2f6111256e47fde43c70035 |
BUDDY_EXECUTION_PREVIOUS_REVISION_MESSAGE The commit message of the previously run revision | last hot fix |
BUDDY_EXECUTION_PREVIOUS_REVISION_SUBJECT The commit subject of the previously run revision | New awesome feature |
BUDDY_EXECUTION_PULL_REQUEST_BASE_BRANCH The name of the Git BASE branch of the currently run Pull Request | master |
BUDDY_EXECUTION_PULL_REQUEST_HEAD_BRANCH The name of the Git HEAD branch of the currently run Pull Request | master/feature1 |
BUDDY_EXECUTION_PULL_REQUEST_ID The ID of the currently run pull request | pull/1 |
BUDDY_EXECUTION_PULL_REQUEST_NO The number of the currently run pull request | 1 |
BUDDY_EXECUTION_REF The branch/tag/pull request or a wildcard string that was used in the pipeline run | refs/heads/branch1 |
BUDDY_EXECUTION_REFRESH Represents whether the files were uploaded from scratch by the deployment actions in the current pipeline run | false |
BUDDY_EXECUTION_REVISION The SHA1 hash of the commit of the current pipeline run | e5e13f8b7f8d5c6096a0501dc09b48eef05fea96 |
BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL The email address of the committer email of the currently run revision | mikebenson@buddy.works |
BUDDY_EXECUTION_REVISION_COMMITTER_NAME The email address of the committer of the currently run revision | Mike Benson |
BUDDY_EXECUTION_REVISION_MESSAGE The commit message of the currently run revision | Create buddy.yml |
BUDDY_EXECUTION_REVISION_SHORT The short hash of the commit of the current pipeline run | e5e13f8 |
BUDDY_EXECUTION_REVISION_SUBJECT The commit subject of the currently run revision | Create buddy.yml |
BUDDY_EXECUTION_REVISION_URL The URL of the commit of the current pipeline run | https://app.buddy.works/myworkspace/my-project/repository/commit/e5e13f8b7f8d5c6096a0501dc09b48eef05fea96 |
BUDDY_EXECUTION_START_DATE The date of the current pipeline run | 2019-01-01T11:27:40.140Z |
BUDDY_EXECUTION_TAG The name of the Git tag of the current pipeline run (provided the run is tagged) | v1.0 |
BUDDY_EXECUTION_TIME The total time of the current pipeline run since the action is triggered (in seconds) | 72 |
BUDDY_EXECUTION_URL The URL of the current pipeline run | https://app.buddy.works/myworkspace/my-project/pipelines/pipeline/1/execution/5d9dc42c422f5a268b389d08 |
BUDDY_EXECUTION_WARNINGS_COUNT The total number of warnings that appeared in the current pipeline run | 3 |
BUDDY_EXECUTION_WEBHOOK_PAYLOAD The payload of the webhook that triggered the pipeline | { "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) | 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 | Upload files |
BUDDY_INVOKER_AVATAR_URL The URL of the avatar of the pipeline run invoker | https://app.buddy.works/image-server/user/0/0/0/0/0/0/1/05d20f3d58ce09a3b4e9g3334a810603/w/32/32/AVATAR.png |
BUDDY_INVOKER_EMAIL The email address of the pipeline run invoker | mikebenson@buddy.works |
BUDDY_INVOKER_ID The ID of the pipeline run invoker | 1 |
BUDDY_INVOKER_NAME The name of the pipeline run invoker | Mike Benson |
BUDDY_INVOKER_URL The URL to the profile of the pipeline run invoker | https://app.buddy.works/myworkspace/profile/1 |
BUDDY_PIPELINE_ID The ID of the run pipeline | 1 |
BUDDY_PIPELINE_NAME The name of the run pipeline | Deploy to Production |
BUDDY_PIPELINE_REFS The list of refs set in the run pipeline | refs/heads/branch1 |
BUDDY_PIPELINE_TARGET_SITE_URL The URL of the server to which the pipeline is deploying | https://buddy.works/ |
BUDDY_PIPELINE_TRIGGER_MODE The trigger mode set in the run pipeline | CLICK |
BUDDY_PIPELINE_REF_NAME The branch/tag/pull request or a wildcard string set in the run pipeline | master |
BUDDY_PIPELINE_URL The URL of the run pipeline | https://app.buddy.works/myworkspace/my-project/pipelines/pipeline/1 |
BUDDY_PROJECT_NAME The name of the project | my-project |
BUDDY_PROJECT_NAME_ID The ID of the project | my-project |
BUDDY_PROJECT_URL The URL of the project | https://app.buddy.works/myworkspace/my-project |
BUDDY_REPO_SLUG The slug of the repository | buddyworks/my-project |
BUDDY_REPO_SSH_URL The SSH URL of the repository | git@github.com:buddyworks/my-project |
BUDDY_SANDBOX_URL The URL of the created sandbox | https://dev-my-project.buddy.cloud |
BUDDY_SCM_PROVIDER The name of the Git hosting provider synchronized with the project | GITHUB |
BUDDY_SCM_URL The URL of the repository synchronized with the project | https://github.com/buddyworks/my-project |
BUDDY_SIGNED_IPA_PATH The path in the pipeline filesystem to which the .ipa file is saved | app-signed/hello_flutter.ipa |
BUDDY_WORKERS The JSON with the information about all installed workers | {"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} | 192.168.4.11 |
BUDDY_WORKERS_ADDRESS_NOT_TAGGED The list of IP addresses of untagged workers | build-server |
BUDDY_WORKERS_AVG_LOAD_${TAG} The average load from the last minute on all workers tagged with ${TAG} | 0.69 |
BUDDY_WORKERS_AVG_LOAD_NOT_TAGGED The average load from the last minute on all untagged workers | 2.03 |
BUDDY_WORKERS_CONCURRENT_SLOTS The total number of pipeline slots across all workers | 4 |
BUDDY_WORKERS_COUNT_${TAG} The number of workers tagged with ${TAG} | 1 |
BUDDY_WORKERS_COUNT_NOT_TAGGED The number of untagged workers | 1 |
BUDDY_WORKERS_FREE_SLOTS_${TAG} The number of free pipeline slots on workers tagged with ${TAG} | 4 |
BUDDY_WORKERS_FREE_SLOTS_NOT_TAGGED The number of free pipeline slots on all untagged workers | 4 |
BUDDY_WORKSPACE_DOMAIN The slug of the workspace | my-workspace |
BUDDY_WORKSPACE_ID The ID of the workspace | 1 |
BUDDY_WORKSPACE_NAME The name of the workspace | My Workspace |
BUDDY_WORKSPACE_URL The URL of the workspace | https://app.buddy.works/myworkspace |
CI Represents whether the current environment is a non-Buddy CI environment | 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.
- The first action builds the application and saves the log output to
logs.txt
:
Primary action (always run)
- In case the build fails, the Local Shell action assigns the content of
logs.txt
to a variable usingexport 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)
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 Run next pipeline action:
- Go into the Variables tab in the action details.
- Define the name of the variable and the value to pass:
Variables 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 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 window
Last modified on February 27, 2023