Updated February 21, 2023
Definition of Bitbucket Environment Variables
Variables are the default values the bitbucket provides to build a code or script. However, according to the requirement, the user can override the present variable with another variable of the same name. The environmental variables are similar to standard variables used to develop containers. The user can access these environment variables from the bitbucket.pipelines.yml file to invoke or refer to them. For example, $bitbucket_secret, here bitbucket_secret is the environment variable’s name. In this article, the configuration, setup, and properties of the environment variable are discussed in brief.
Bitbucket environment variables overview
Multiple environment variables are available in bitbucket, and every variable serves its unique purpose. Few widely used variables are user-defined variables and workspace variables. In the user-defined variables, the user can add, remove or edit the account name repository name and modify the deployment environmental levels. If the user has to work on it with the same name as the existing variable, he can change or override it. But the override order needs to be followed in steps like choose deployment -> to choose repository -> Account -> select default variables. Every deployment variable is independent so that the user can avail of the same variable name with varied values for each environment. The names should contain only underscore, digits, and ASCII letters, and they cant begin with digits. The case-sensitive names should be given. The variables defined in the shell should not be availed. But it is possible, by using the command, printeny
Repository variables are added to the repository level and can be done by any user with write access. The user should be an admin to configure and access the repository variables. The user can choose repository variables to override the account variables in the repository’s settings.
The secured variables are used to compose scripts, but the values are hidden in the build logs. If users want to edit the secure variable, they can provide any new value or edit it. The secured values can be saved as encrypted values, and he can secure the variable with a padlock. The pipelines mask the secured variables, which team members cannot view to build scripts. If the value is matched with secured variables, it can be replaced by the $ name of the variable.
Set bitbucket environment variable
The user can declare the environment variable in the server.yml file in the bitbucket.pipelines.yml. If the user has the same issue before executing it, he can follow the below steps,
- Navigate to repository settings
- Then choose pipelines and select repository variables. The user can also define the variables in the deployment option.
- Declare the variables which need to be configured in the bitbucket.pipelines.yml
- Declare the variables from the bitbucket.pipelines.yml to the server.yml.file, which can be fed to the application.
How do bitbucket environment variables?
The user can configure the environment variable based on scanning Veracode software analysis. To choose the variables at the account level. Navigate to account, then click bitbucket settings. Then choose the team to configure the variables. From the left pane, choose pipelines, then select environment variables. Enter SRCCLR-API-TOKEN in the type variable field, and the type value filed, and give the API token. Then verify the secured box and ensure it is selected. Then choose to add.
The environment variables are added on the repository level, which all the users can manage with push permission. First, the user can configure the environment variable to execute the scan on the new build code. Then in the settings, choose the environment variable, give the API token, and ensure the checkbox is selected. Next, add the default configuration script in the bitbucket.pipelines.yml file to scan the composition values. Finally, the changes can be made to build the repository where the SCA scan and display the result to the scanning environment based on agents. If the user wants to add the scanned result to other repositories, he can add it via installation and execute the code to any bitbucket.pipelines.yml file according to the requirement. After adding the SRCCLR token, the user can perform a new scan on every new build or code script.
Configure the bitbucket environment variable
The agent can make the bitbucket environment configuration visible only to workspace members where the agent is created. To enable visibility, the team members can be invited to the workspace. The scan and analysis are chosen in the platform, and the agent-based scan is opened. Choose workspace. Then select agents followed by actions -> create and CI. Then agent can be created, and the token is generated. The value is copied in the token area. The token is used as authentication criteria and can be applied accordingly. The user can scan the circleCI environment in the repository, navigate project settings, and choose the environment variable. Then select add a variable, for name and value field, given token name and token value. Ensure that the display value in the build log turns off and the token is hidden. Then the user can add the variable.
Bitbucket environment variables examples
The variables used in a workspace can be used from all repositories, and the user has to be an admin to access it. These are called workspace variables. From the console, choose a workspace in the left button, then go to workspace settings; in the menu, the user can choose pipelines and workspace variables. These workspace variables can be overridden with repository variables. All the users can avail of it with only written permission for any public or private repository that belongs to the account or team. The user should be the admin of the repository to manage the variables respectively.
Conclusion
Hence in this article, a brief note on environment variables in bitbucket is discussed. The configuration, examples, and settings of environment variables in bitbucket can be modified according to the user requirement. Therefore, it can be used instantly whenever required, and other account members can also access it.
Recommended Articles
This is a guide to Bitbucket Environment Variables. Here we discuss the Introduction overviews; Create Logstash multiple pipelines Examples with code implementation. You may also have a look at the following articles to learn more –