Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Using envionment variables for database connection string

Sushil Nembhani December 26, 2019

Hi All,

I have currently java application which has the database.properties file for storing the connection string, user & password.

Instead of storing these details in the bitbucket repository i would like to use the environment variables.

How would i do this using the Bitbucket pipeline or Bamboo ?

regards,

Sushil

1 answer

1 vote
Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 27, 2019

Hi @Sushil Nembhani

It is difficult to understand what part of this process you are looking for just from your question. Do you want to know how to declare the variables, how to consume them in the JAVA application, how to run the declare password variables...?

Regarding the variables for Bamboo, I encourage you to check this document:

  • Bamboo variables - Atlassian Documentation
    It will share other pages that will give you details about the global, plan and deployment variables.
    ⚠️ If you are attempting to use a Bamboo variable in a script task, please make sure you reference it with the naming convention they have when showing in the terminal.
    The variable ${bamboo.my.var} would be available as $bamboo_my_var .

Regarding Pipelines ones, please check this one:

You will need to choose where is the best location to store the variable you need.

If you are looking for tips on how to load the variable data into your JAVA application through a script or terminal, then I think this is not the ideal forum. I would encourage you to drop this question on a JAVA specific one.

I hope I could help.

Sushil Nembhani December 27, 2019

Hi Daniel,

My first question is instead of storing the database connection string , user name & password in bitbucket, how can i use the environment variables so that i do not have to change the config file when i moved from dev to staging to prod ?

My second question is should i be using environment variables provided in bamboo or use the variables in the bitbucket pipelines as both do provide the option to use environment variables ?

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 30, 2019

Let me share how I see you could do this for Bamboo. A similar solution could be used in case you are deploying your project using Pipelines.

  1. Create a deployment project with environments for dev, staging, and production.
  2. Create the variables you need for user, connection string, password (and any other needed) with the same name in all three environments.
  3. Design your application to read those variables
  4. Each variable will have a different value configured for it but the same names and that will allow you to have different values for each environment.

I was a little bit confused because I was considering that you were talking about two different solutions, one for Bamboo and another for Pipelines. I'm now thinking that you are only using Bamboo connected to Bitbucket and considering that Bitbucket Pipelines variables could be used in Bamboo. Am I correct?


Sushil Nembhani December 30, 2019

Thanks for providing the details.

I am currently using both bitbucket & bamboo for the entire devops CI/CD.

I would like to know for my case if i need to use the environment variables within Bitbucket or Bamboo for the storing the connection string details.

Also how would my application (Java or .net) read the bamboo/bitbucket environment variables, i could not find any sample case studies or sample code showing the same.

Regards,

Sushil Nembhani

Daniel Santos
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 3, 2020

Hi @Sushil Nembhani

If you are running Pipelines builds you need to use Bitbucket variables, if you are using Bamboo builds you need to use Bamboo variables. You need to have the variables set in the same build environment running. You cannot use Bamboo variables in Bitbucket Pipelines or vice-versa.

Regarding the way to read the variables, as I shared before, that is a matter of JAVA or .net technology that is not related to Bamboo or Bitbucket. You will need to research this specifically on other channels. I've just run a search for this and found a thread in stack overflow for the JAVA case: Can we read the OS environment variables in Java? - Stack Overflow.

The variables will be available in the build environment when the application is running or when the compilation is running. You will need to seek methods to read them that will be handled by the tool you are using at that moment. For instance, anything that works in the OS terminal should work under Bamboo as well.

Sushil Nembhani January 4, 2020

Thanks Daniel. I will check in bamboo as per the steps provided by you.

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events