Hi,
It would appear that the githib k6 run action does not allow environment variables to be used in the options object of a test.
Here are screenshots of minimal examples of the test.js and load-test.yaml files
Please note that there may be a syntactic mistake or 2 but hopefully the concept is still clear.
When the action is executed in github, the following error message is displayed.
Validating test run files.
time=2025-05-15T10:03:36Z level=error msg=TypeError: Cannot read property ‘threshold_http_req_failed_rate’ of undefined\n\tat file:///home/runner/actions-runner/_work/test.js:21:50(xx)\n hint=script exception
This same script works when run locally: k6 run --env TEST_DURATION=5m --env TARGET_ENVIRONMENT=integration - <test.js
And it also works when manually installing and running k6 in the github workflow file instead of using the setup and run actions.
I suspect it may have something to do with the script validation step of the github run action as there does not seem to be a validation step when running locally
Any ideas what I might be doing wrong.
Thank you in advance.
Morné
Hi @mornemaritz,
Welcome to our community forums! 
This same script works when run locally: k6 run --env TEST_DURATION=5m --env TARGET_ENVIRONMENT=integration - <test.js
I see in this case, you’re explicitly passing the environment variables through the --env
flag.
So, I’d suggest trying to do the same with the flags
option of the run-k6-action
.
Note that the env
section is part of the GitHub Workflows job definition, not specific to k6.
I hope that helps! 
Cheers!
Hi @joanlopez,
Thank you very much for your very quick response and your suggestion.
Unfortunately, this doesn’t seem to have solved the problem. I applied the suggested changes to my actual yaml file, as indicated in the screenshot below of the updated version of the minimal example and the error still occurs.
Kind Regards,
Morné
Hi,
Another interesting observation is that the issue with env variables seems to only occur in the options object.
For instance, this combination of test and yaml files works fine where only the url in the main test function uses an environment variable.
Kind Regards,
Morné
Hi @joanlopez,
You suggestion actually turned out to be the correct one. There was just a slight difference in how the github action expects flags
to be specified.
Upon inspecting the source code of the github action I noticed that it runs an inspect
command which does not seem to include values specified for the flags
option but only includes the values specified for the inspect-flags
option
Specifying the relevant --env
values for both the flags
AND the inspect-flags
options results in the github action completing successfully.
Once again, thank you for setting me on the correct path.
Kind Regards,
Morné
1 Like