Github run action does not allow env variables in option object?

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.

:magnifying_glass_tilted_left: 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! :tada:

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! :crossed_fingers:
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

Hi @mornemaritz
I’m currently facing an issue with the grafana/run-k6-action in GitHub Actions. I’m trying to pass environment variables like MODULES_TO_RUN and TEST_NAME to my k6 test script. These variables work perfectly when I run the test locally using:
6 run --env MODULES_TO_RUN=MilestoneTemplate --env TEST_NAME=“Cloud Run” script.js
But in github, even after setting:-
flags: “–env MODULES_TO_RUN=MilestoneTemplate --env TEST_NAME=CloudRun”
The issue is not resolved.
Can you please help me out of this situation.
Thank you in advance.

Hi @neha29,

If you think there’s any issue with the GitHub Action, then I’d suggest you to fill an issue in the action’s repository, with all the details and the smallest possible example to reproduce the issue.

There you should get help from the action’s maintainers, and if there’s really an issue (like a bug or similar), they’ll likely fix it in a timely manner.

I hope that helps,
cheers!