Running parallel kubernetes jobs in Jenkins pipeline

19 views
Skip to first unread message

Alex Taran

unread,
Aug 3, 2020, 4:11:15 PM8/3/20
to Jenkins Users

I'm running perfomance tests on 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 
  completions: 2 
  backoffLimit: 1 
  ttlSecondsAfterFinished: 100 
  template:
    spec:
      initContainers:
      - name: nft-tests-downloader
        image: git
        command: ['sh', '-c', "git clone --depth 1  --branch master https://some.org.com/repo.git /tmp/nft/;chown 1000:1000 /tmp/nft_logs"]
        securityContext:
        volumeMounts:
        - mountPath: /tmp/nft
          name: nft-tests
        - name: nft-test-logs
          mountPath: /tmp/nft_logs
      containers:
      - name: jmeter
        image: jmeter
        command: ["/bin/sh","-c"]
        args: ["jmeter run performance test"]
        tty: true
        imagePullPolicy: Always
        securityContext:
            runAsUser: 1000
        volumeMounts:
            - mountPath: /tmp/nft
              name: nft-tests
            - name: nft-test-logs
              mountPath: /tmp/nft_logs
      restartPolicy: OnFailure
      volumes:
      - emptyDir: {}
        name: nft-tests
      - name: nft-test-logs
        persistentVolumeClaim:
              claimName: nft-test-logs

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).
If someone had experience with it, please share your workarounds or ideas how to implement this idea.

Reply all
Reply to author
Forward
0 new messages