Bitbucket Pipelines provides a set of default environment variables as well as the ability to define your own variables. You can mark variables as secured for additional security of your passwords, tokens, and other values.
See also What is a slug?
Variables are set as environment variables in the build container. You can access the variables from the bitbucket-pipelines.yml file or any script that you invoke by referring to them in the following way:
AWS_SECRET is the name of the variable.
Pipelines provides a set of default variables that are available for builds, and can be used in scripts.
You can override the default variables by specifying an environment variable with the name of a default variable.
||Default value is
||The unique identifier for a build. It increments with each build and can be used to create unique artifact names.|
The absolute path of the directory that the repository is cloned into within the Docker container.
||The commit hash of a commit that kicked off the build.|
||The name of the account in which the repository lives.|
||The UUID of the account in which the repository lives.|
||The URL-friendly version of a repository name. For more information, see What is a slug?.|
||The UUID of the repository.|
The branch on which the build was kicked off. This value is only available on branches.
Not available for builds against tags, or custom pipelines.
The tag of a commit that kicked off the build. This value is only available on tags.
Not available for builds against branches.
||For use with Mercurial projects.|
Zero-based index of the current step in the group, e.g. 0, 1, 2, …
Not available outside a parallel step.
Total number of steps in the group, e.g. 5.
Not available outside a parallel step.
You can add, edit, or remove environment variables at the account and repository levels. Variables specified at the repository level override variables specified at the account level.
Names can only contain ASCII letters, digits and underscores
Names are case-sensitive
Names can't start with a digit
Environment variables added at the repository level can be accessed by any users with the push permission in the repository.
You can manage repository variables in Settings > Pipelines > Environment variables .
Repository variables override team variables.
Team and individual account variables
Environment variables specified for a team or an individual account can be accessed from all repositories that belong to the team or account. You must be an administrator to manage team variables.
To manage team or individual account variables:
- From your avatar in the bottom left, click Bitbucket settings.
- Select an individual account or a team for which you want to configure variables:
- In the menu on the left, go to Pipelines > Environment variables.
Team or individual account variables can be overridden by repository variables.
Team or individual account variables can be accessed by all users with the write permission for any repository (private or public) that belongs to the team or account.
You must be an administrator of an account or a repository to manage variables respectively.
You can secure a variable, which means it can be used in your scripts but its value will be hidden in the build logs (see example below). If you want to edit a secure variable, you can only give it a new value or delete it. Secure variables are stored as encrypted values.
Secured variable masking
Pipelines masks secure variables so they are not disclosed to your team members viewing build logs. If a value matching a secured variable appears in the logs, Pipelines will replace it with
This can lead to confusion about whether secured variables are working properly, so here's an example of how it works.
First, we have created a secure variable,
MY_HIDDEN_NUMBER, with a value of 5.
Then we used this
pipelines: default: - step: script: - expr 10 / $MY_HIDDEN_NUMBER - echo $MY_HIDDEN_NUMBER
The value of the variable can be used by the script, but will not be revealed in the logs. It is replaced with the name of the variable,
Note: Pipelines masks all occurrences of a secure variable's value in your log files, regardless of how that output was generated.
If you have secure variable value set to a common word, that word will be replaced with the variable name anywhere it appears in the log file. Secured variables are designed to be used for unique authentication tokens and passwords and so are unlikely to be also used in clear text.
Pipelines also matches some basic encodings of the variable value, like URL encoding, to prevent variables being displayed when used in URLs.