[英]Running parallel kubernetes jobs in Jenkins pipeline
I'm running perfomance tests on Jenkins.我正在对 Jenkins进行性能测试。 Test that may include multiple instances of the same container to generate necessary load.测试可能包括同一容器的多个实例以生成必要的负载。 I can't hardcode number of instances as it varies based on params for tests.我无法对实例数量进行硬编码,因为它会根据测试的参数而变化。 I've tried to use the following code:我尝试使用以下代码:
pipeline {
agent any
stages {
stage('Running Jmeter') {
agent {
kubernetes {
label "jmeter_tests_executor"
yaml '''
apiVersion: batch/v1
kind: Job
metadata:
name: jmeter
namespace: jenkins
spec:
parallelism: 2
backoffLimit: 1
ttlSecondsAfterFinished: 100
...
But it doesn't work.但它不起作用。 It's hanging on pod scheduling(jobs works ok if you apply this manifest directly on kubernetes cluster without Jenkins).它挂在 pod 调度上(如果您直接在没有 Jenkins 的 kubernetes 集群上应用此清单,则作业可以正常工作)。
If someone had experience with it, please share your workarounds or ideas how to implement this idea.如果有人对此有经验,请分享您的解决方法或想法如何实现此想法。
Maybe try something like this也许尝试这样的事情
stage("RUN LOAD TEST") {
steps {
script {
//params.each creates an array of stages
paramsToTest.each {param ->
load["load test"] = {
stage("Executing run ${param}") {
agent {
kubernetes {
label "jmeter_tests_executor"
yaml '''
apiVersion: batch/v1
kind: Job
metadata:
name: jmeter
namespace: jenkins
spec:
parallelism: 2
backoffLimit: 1
ttlSecondsAfterFinished: 100
...
'''
}
}
steps {
<EXECUTE LOAD TEST COMMAND>
}
}
}
parallel(load) //actually executes the parallel stages
}
}
}
}
What this does is use an array of something and then generates stages based on that array.这样做是使用一个数组,然后基于该数组生成阶段。 The agent params in the stage should tell Jenkins to create a new pod with each execution in parallel.阶段中的代理参数应该告诉 Jenkins 创建一个新的 pod,每个执行都并行执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.