bruno icon indicating copy to clipboard operation
bruno copied to clipboard

[Bug] process.env is empty in all script environments

Open mjhcorporate opened this issue 11 months ago • 1 comments

I have a .env file in my collection root. The contents are:

MY_SECRET=123456

I can use this in request headers like so: image

But when I try to use it in any of the scripting environments, the value is always null: image

For reference, this is my bru file:

meta {
  name: Todo1
  type: http
  seq: 3
}

get {
  url: https://jsonplaceholder.typicode.com/todos/1
  body: none
  auth: none
}

headers {
  my_header: {{process.env.MY_SECRET}}
}

script:pre-request {
  console.log(process.env.MY_SECRET)
}

script:post-response {
  console.log(process.env.MY_SECRET)
}

tests {
  console.log(process.env.MY_SECRET)
}

mjhcorporate avatar Mar 06 '24 12:03 mjhcorporate

Workaround: You can define an environment variable like this: image

And then use it via the familiar bru.getEnvVar("the_workaround") syntax.

mjhcorporate avatar Mar 06 '24 12:03 mjhcorporate