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);
};