5

As indicated in the official loadimpact/k6 documentation, we are able to execute k6 scripts as follows:

k6 run github.com/loadimpact/k6/samples/http_get.js

Is it possible to pass in custom command line arguments into a k6 test? For instance, let's say that I would like to pass in a URL and then reference this URL from within the script.

Is this supported out of the box? If so, how can I accomplish this?

101010110101
  • 1,940
  • 8
  • 31
  • 42

2 Answers2

7

This use case is actually covered very well in the documentation, I just happened to miss it.

https://docs.k6.io/docs/environment-variables

101010110101
  • 1,940
  • 8
  • 31
  • 42
3

For single argument: k6 run -e ENVIRONMENT=test2 scripts/test2GetWorkOrder.js and For multiple arguments: k6 run -e ENVIRONMENT=test2 -e WOID=107376 scripts/test2GetWorkOrder.js

you need to put a "-e" before every argument you pass through the script.