0

I am trying to do load testing in jenkins pipeline using k6 open-source platform. The below given code is my Jenkinsfile to run load testing. when I try 'k6 run loadtests/performance-test.js', I get the perfect output in the jenkins console. But 'k6 cloud oadtests/performance-test.js' throws error. I have added k6 credentials in jenkins as well.

pipeline {
    agent any

    environment {
        K6_API_TOKEN=credentials("K6_API_TOKEN")
        K6_CLOUD_PROJECT_ID=credentials("K6_CLOUD_PROJECT_ID")
      
    }
    stages {
        stage('Performance Testing') {
            steps {
                echo 'Running K6 performance tests...'
               
                echo 'Let us login into k6'
                sh 'k6 login cloud --token ${K6_API_TOKEN}'
                
                echo 'login successful'
                sh 'k6 cloud loadtests/performance-test.js'
                echo 'Completed Running K6 performance tests!'
            }
        }
    }
}

but when I run this,

Let us login into k6
[Pipeline] sh
+ k6 login cloud --token ****
  token: ****
[Pipeline] echo
login successful
[Pipeline] sh
+ k6 cloud loadtests/performance-test.js

          /\      |‾‾| /‾‾/   /‾‾/   
     /\  /  \     |  |/  /   /  /    
    /  \/    \    |     (   /   ‾‾\  
   /          \   |  |\  \ |  (‾)  | 
  / __________ \  |__| \__\ \_____/ .io

Init   [   0% ] Parsing script
Init   [   0% ] Getting script options
Init   [   0% ] Consolidating options
Init   [   0% ] Building the archive
Init   [   0% ] Validating script options
time="2021-03-23T17:45:55Z" level=error msg="(500) Internal error"

ERROR: script returned exit code 255
Finished: FAILURE

The below is my performance-test.js file

import { sleep } from"k6";
import http from "k6/http";

export let options = {
  duration: "0.30m",
  vus: 50,
 
};

export default function() {
  http.get('http://test.k6.io/contacts.php');
  sleep(3);
};

1 Answers1

1

I'm able to run the script myself with k6 cloud, so I suspect the problem has to do with your ${K6_API_TOKEN}. I would try echoing the value before using it in the k6 login cloud --token command so you can confirm that it is indeed being set properly and that it is a valid API key.

I'm able to reproduce a HTTP 500 response myself if I set the token to some unexpected value, like .. Perhaps we could use some validation when setting the token using k6 cloud login --token.

As a side note, if your intention is to run the script for 30 minutes, you should use duration: 30m without the preceding 0.

Tom
  • 126
  • 1