-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to set custom variables? #1101
Comments
I'm not sure I fully understand your use case, but maybe the k6 environment variables would be a suitable solution? You can specify them via the CLI like this: |
Thanks for the quick response! So for context I'm moving to k6 from Artillery. The specific functionality I was trying to replicate is their inline variables. This allowed me to have a config file for every environment I wanted to test and change various variables for each while not impacting the scripts. I did notice the environment config option but it was starting to get a little cumbersome as I needed to set quite a few of them (around 10). I was hoping to find a way to do this succinctly with k6 config files as I already have those created to set the stages, etc... for each environment. Guess for now I'll need to have a separate envvar file and config file per environment. If it was possible to even set envvars in the config file like other k6 options that would satisfy my use case. |
Unfortunately it isn't possible, you can only specify k6 options in the .json config file (either the default one or any custom one you specify with The inability to specify environment variables there is mostly because the environment variables in k6 are a bit more flexible, but that same flexibility offers a pretty easy workaround for your use case. You can use these environment variables to specify your own custom config file, import http from "k6/http";
let myOptions = JSON.parse(open(__ENV.MY_CONFIG_FILE));
export let options = {
vus: myOptions.myCustomVUs,
stages: myOptions.stages,
};
export default function () {
http.get(`https://${myOptions.myEnv.myHostname}/whatever`);
} Then you can run that script with |
Yeah I did have a similar thought. Will give that a try for now and close this. Would be good to see custom variables supported natively though. Cheers! |
We plan to do something like that with the new executors. It will be done either in #1007 or in a follow-up PR, but in essence you'd be able to specify environment variables per executor, so as part of the normal options. |
Is there (or can they be) a way to set custom variables in options that can then be referenced in scripts? I'm looking for a way to change what URLs and variables scripts will use based on the config file I load for flexibility. Cheers.
The text was updated successfully, but these errors were encountered: