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
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.
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.
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.
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.
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.