Environment variables are pairs of key-and-value that can be used in the pipelines instead of manually updating the same values. They allow developers to save time looking up and entering access details, and eliminate the risk of providing sensitive details in their scripts.
ENV VARs are used to parameterize build scripts. Setting up variables in a pipeline will cause the same build action to work differently depending on the pipeline.
Setting Environment Variables
When adding a new variable, the following fields are available:
- Scope – defines the level of the variable
- Encryption – enabling encryption will hide the value of the variable in the logs
- Type – if you set it to Fixed, the value of the variable will always be the same. Switching the option to Settable will let you change the value and pass it to the next action or execution
Environment Variables can be defined on 4 levels:
- Workspace – available for all projects and pipelines. Configured in the workspace Preferences.
- Project – available for all pipelines in the project. Configured in the Project Options.
- Pipeline – available only for the pipeline where was created (eg. production server details). Configured in the pipeline details.
- Action - available only for the actions where the variable was defined
Each subsequent tier will overwrite the value from the higher tier. For example, if you have two same variables – one 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 account.
You can learn more about passing parameters here.
Let's configure some variables to encrypt access to an FTP server:
- Go to your deployment pipeline and click the Variables tab
- Add variables with the corresponding values. For example:
- Now you can use the variables to store access credentials to your deployment server:
Fields that support ENV VARs
Environment variables are supported across the whole service, but most commonly used in the build actions. You can predict a variable by entering
$ in the supported field:
Here's the list of the currently supported fields:
|Action Name||Supported Fields|
|Amazon_S3||SourcePath, Remote Path|
|Android_Publish||APK, Main Expansion File, Patch Expansion File, Service Account Key, Package Name, Mapping File, Changelog|
|Android_Sign||Select the APK, Location, KeystorePassword KeyAlias, OutputDirectory, Output APK Name|
|Bugsnag||API Key, Version, Revision, Builder Name, Release Stage|
|Code_Deploy||SourcePath, BucketName, Description|
|Datadog||Event Title, Content, Host, Tags, Aggregation Key|
|Digital_Ocean||SourcePath, Port, Login, Password, Remote Path, SSH Key Passphrase|
|Digital_Ocean_Spaces||SourcePath, Remote Path|
|Docker_Push||Login, Password, Repository, Tags|
|Elastic_Beanstalk||SourcePath, VersionLabel, BucketName|
|FTP||SourcePath, Hostname, Port, Login, Password, RemotePath|
|FTPS||SourcePath, Hostname, Port, Login, Password, RemotePath|
|GIT||URL, Login, Password, Commit Message|
|Google_App_Engine||SourcePath, Bucket, Version, ImageURL|
|HTTP||EndpointURL, Login, Password, UserAgent, ContentType|
|Kubernetes_Apply||Server, Username, Password, SourcePath, PruneWhitelist, GracePeriod|
|Kubernetes_CLI||Server, Username, Password|
|Kubernetes_Run_Job||Server, Username, Password, Yaml|
|Kubernetes_Run_Pod||Server, Username, Password, Yaml|
|Kubernetes_Set_Image||Server, Username, Password, ImageName, ImageTag|
|Pushover||Title, URL, URL Title|
|Raygun||Access Token, API Key, Version, User, Email, Comment|
|Replace||SourcePath, Replacements (name)|
|Rollbar||Environment, Comment, Username, Rollbar Username|
|Rsync||SourcePath, Hostname, Port, Login, Password, RemotePath|
|Run_Docker_Container||Login, Password, Image, Version|
|Sentry||Release Version, Deploy Environment|
|SFTP||SourcePath, Hostname, Port, Login, Password, RemotePath|
|SSH||SourcePath, Hostname, Port, Login, Password, RemotePath|
|TCP||Host, Port, String To Send, String To Expect|
|Upcloud||SourcePath, Port, Login, Password, RemotePath, SSH Key Passphrase|
|Vultr||SourcePath, Port, Login, Password, RemotePath|
|WEB||URL, Check For String, Login, Password, UserAgent, ContentType|
|WEB_Dav||SourcePath, Hostname, Login, Password|
|ZIP||SourcePath, TargetPath, FileName|
If you didn't find your action here or the required field is unsupported, let us know on the live-chat or drop a line at email@example.com.
Some fields are HTML textareas and do not support variable suggestions, e.g. message fields in notifications. They do support ENV VARs perfectly fine, however.
Default Environment Variables
Buddy populates 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:
Passing variables between actions
Passing variables within one pipeline is useful, e.g. when we want to assign file content to a variable and send it in a notification:
- The first action builds the application and saves the log output to
- In case the build fails, the Local Shell action assigns the content of
logs.txtto a variable using
export LOGS=$(cat log.txt).
- The logs are then sent to a Slack channel with
$LOGSas the message content.
Make sure to set the variable to 'Settable', otherwise it will not be possible to change its value.
Passing variables between executions
You can pass the values of variables between executions as well. The values can be saved in one execution and then used in another one, e.g. you can set a variable with the version type and increment it in every execution.
You can read more about semantic versioning in our dedicated guide.
Passing variables between 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:
You can assign any variable from the target pipeline as the value.
Passing variables on execution start
You can parameterize your execution using the Pass arguments action – it will pause the pipeline and wait for your input to proceed:
Learn more about passing variables here.