Cloud login failure from GItLab CI

I am trying to configure k6 cloud with my GItLab CI pipeline following below document.

I am able to login to k6 cloud account .


Created new project and have project id and token.
Same token I have used in GItLab variables as K6_CLOUD_PROJECT_ID & K6_CLOUD_TOKEN.

.gitlab-ci.yml configuration for k6 cloud

- echo “executing cloud k6 in k6 container…”
- test -f codegen/openapi.json
- k6 cloud build/k6.bundle.min.mjs

When I am running pipeline getting an error below.
$ k6 cloud build/k6.bundle.min.mjs

time=“2023-07-17T04:21:46Z” level=error msg=“Not logged in, please use k6 login cloud.”

Hi @tailorravat

Thanks for pointing to this blog. It has some older screenshots and links to GitLab that have changed. I am making a note to update those soon to make it easier to follow.

Does it fail before you even execute via GitLab CI/CD or only locally?

You mention the error you get when you execute locally k6 cloud build/k6.bundle.min.mjs? The blog does not have instructions for that, you would follow Cloud tests from the CLI to run locally. Instructions for CI/CD are different. E.g. K6_CLOUD_TOKEN=<YOUR_K6_CLOUD_API_TOKEN> k6 cloud script.js

If it fails when running in GitLab/CD let us know, and share how you define them. I was able to make it work following the blog as well. However, depending on how you create the variables in GitLab it could cause this. And we can always update the blog to make update the instructions.


Thank you @eyeveebe for reply.

Yes I am able to run successfully from my local.
k6 login cloud --token <cloud_token>
k6 cloud --http-debug=full build/k6.bundle.min.mjs

And I am able to see graph on grafana board, But error occurs with GitLab CI.

I have setup the variable for both project id and token in GitLab Variables.

Hey @eyeveebe.

It worked with
- echo “executing cloud k6 in k6 container…”
- test -f codegen/openapi.json
- k6 login cloud --token access_token
- k6 cloud build/k6.bundle.min.mj.

thanks for some guidance.

Hi @tailorravat

Thanks for getting back. I think you should not have to explicitly login. Creating the variables like this worked for me at the project level.

I used a basic test:

import http from 'k6/http';

export const options = {
    duration: '10s',
    vus: 2,
    thresholds: {
        http_req_duration: ['p(95)<1200'], // 95 percent of response times must be below 2 seconds

export default function () {
    // simple request delayed 1 second

And GitLab could log in and execute in the k6 cloud with the pipeline in the example.

Can you share how you created the variables? I suspect this could be the issue, maybe something changed in GitLab defaults for variables since this blog was posted, and we need to specify clearly in the instructions.


Hi @eyeveebe .

I have created project level variable as you defined in screenshot, I have got the access_token after login to prometheus grafana account and project id I got from project i created.

But still I need to explicitly login to k6 cloud, local also I need to same thing.

Please let me know if I am still not able to explain the thing properly, or you need more specific details.

Hi @tailorravat

Did you create the access token in the k6 app settings or Prometheus? I guess you did create the token in the k6 app but I was not sure based on your last comment:

Also, for the variables on GitLab, what attributes do you have? Can you share a screenshot similar to mine, so we can make sure the variables are created with the same attributes and in the right place? It looks safer to use variables for secrets, as they will be masked.


Hi @eyeveebe ,

I created the access token in prometheus.

And got the issue now, token was protected and I was running it from my unprotected branch.

Thanks alot for timely reply.

1 Like

Hi @tailorravat

A quick update to this thread: I updated the GitLab blog post and mentioned being careful with creating the variables to ensure they have the correct attributes.

Thanks for pointing this out. It will for sure help other users.