Accesing __ENV. variables from extension


If I run this

k6 run -e script.js

I know how to retrieve an env value in the js script:

import http from 'k6/http';
import { sleep } from 'k6';

export default function () {
  const res = http.get(`http://${__ENV.MY_HOSTNAME}/`);

But how can I retrieve it from the go code in an extension? Did anyone achieve it?

I tried this but it do not work

os.LookupEnv("MY_HOSTNAME") (

Thanks very much

Have you tried os.Getenv("MY_HOSTNAME")?

1 Like


as mentioned, os.Getenv should be what you’re looking for :+1:

On top of that, because naming is hard, I wanted to raise your awareness that in your example what you referred to as a “hostname” was in fact a URL :bowing_man:


Finally I understood how it works, and what I need is really os.Getenv(“MY_HOSTNAME”).

Many thanks for the answers!

1 Like