Group of environment variables for GitLab variables

Hello all, relatively new but enthusiastic k6 user. I am struggling with how to define multiple environment variables into a single variable group which would be used in GitLab variables for CI/CD and cronjob tests. Like 1 group for all of the Dev-related variables and 1 for all the Test-related ones. The GitLab integration is working well but I have not been able to figure out how to avoid defining every test variable singly as GitLab variables. A few of these are confidential and must be protected (userid/pw credentials); most of the variables are not secret but I do need to use them in a parameterized fashion and the command statement is already starting to get long due to the individual references. I’m barely getting started with the microservices tests, but already the GitLab variables are already getting a little unwieldly in terms of the length of the run statement in the CI file due needing to call the hostnames, all the authentication fields, etc. Quick picture of my situation:

  • Over 100 microservices and growing
    • Common Dev and Test environments for all 100, routing controlled by API path
  • 15 different web applications and about 20% of the services are common across some of the web apps
    • Each of the 15 have their own Dev and Test environment
  • Keycloak authentication for both services and web apps.
    • The Keycloak Dev and Test environments are common for Dev and Test, but they are different hosts than the above
  • 5 scenario files shared across scripts depending on pipeline stage and overall test objective (the various k6 Options such as stages, executors, thresholds). I’m calling the entire scenario on the command line with an environment variable [JSON.parse(open] but since these are checked into the repo they do not need to be defined as GitLab variables.
  • Creating one script for each service that can be used locally against either Dev or Test (perhaps different use cases controlled with tags), then configured in GitLab and against both Dev and Test.
    • Call each script in isolation (CI/CD pipelines) then in specific combinations (scheduled jobs)
  • Creating one script for each web application…

After further research I believe the solution is to define the group of variables in GitLab and have a shell script parse them before the k6 script runs. I will update with my conclusions.

One additional thing to consider may be to use a customized version of k6 using xk6 with the xk6-dotenv community-supported extension.

This won’t help on your secret settings, but at least you’d be able to inject variables based upon environment, then your test scripts can utilize those.