4

I have my sensitive data as environment variables in Bitbucket Pipelines, e.g. database credentials. Is there a way I can access these environment variables from my source code? I do not want to push these sensitive data to my repository.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
user6754
  • 71
  • 1
  • 8
  • yeah i mean Bitbucket pipelines.I want to access environment variables in environment.ts file, so once I push the code ng build should access API_HOST and PORT in environtment.ts and build a /dist folder.But i do not want these things in my repo so i am putting them in environment variables. – user6754 Aug 28 '17 at 12:44

1 Answers1

4

Bitbucket Pipelines environment variables are just regular environment variables. You can access them however you normally would; this depends on the programming language you are using.

For example, in Python you can use os.getenv(), which lets you optionally provide a default value to use in case the desired environment variable isn't available.

Without knowing more about your technology stack it's impossible to provide a more specific answer.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • but in javascript applications, we get env variables like `process.env.VARIABLE` BUT there it is undefined – Zain Khan Mar 01 '22 at 13:53
  • @ZainKhan, what kind of JavaScript applications are you talking about? For server-side Node.js they should be defined. In-browser code, like React or Vue.js, doesn't have access to the server's environment. They require a different strategy. – ChrisGPT was on strike Mar 01 '22 at 13:54
  • yes, I'm using React and here is the question https://stackoverflow.com/questions/71309601/bitbucket-pipelines-not-getting-env-variables – Zain Khan Mar 01 '22 at 13:57
  • and also apart from it, I'm also struggling to deploy my Django app to ec2 using bitbucket pipelines, do you have any idea about that? – Zain Khan Mar 01 '22 at 13:59