我正在尝试使用k6开源平台在jenkins pipeline中进行负载测试。下面给出的代码是我用来运行负载测试的testing文件。当我尝试'k6 run loadtest/performance-test.js‘时,我在jenkins控制台中得到了完美的输出。但是'k6 cloud oadtest/performance-test.js‘抛出错误。我还在jenkins中添加了k6凭据。
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!'
}
}
}
}但是当我运行这个的时候,
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下面是我的performance-test.js文件
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);
};发布于 2021-03-24 03:08:05
我可以自己用k6 cloud运行这个脚本,所以我怀疑这个问题与您的${K6_API_TOKEN}有关。在k6 login cloud --token命令中使用该值之前,我会尝试回显该值,这样您就可以确认它确实设置正确,并且是一个有效的API键。
如果我将令牌设置为某个意想不到的值,比如.,我可以自己重现HTTP500响应。也许我们可以在使用k6 cloud login --token设置令牌时使用一些验证。
另外,如果您打算运行该脚本30分钟,则应该使用不带前面的0.的duration: 30m
https://stackoverflow.com/questions/66768991
复制相似问题