dockerkubernetesjenkinstestcontainerscloudbees

Run testContainers inside kuberenetes pod


I have to run integration tests inside a container which is inside a kuberenetes POD.

I have the folowing jenkinsfile:

!groovy
pipeline {
agent {
 kubernetes {
 yaml libraryResource('podTemplates/pod.yaml')
}
}

  stages {

      stage('Checkout from VCS') {
        steps {
          checkoutScm()
        }
      }

      stage('Integration Testing') {
       steps {
         container('maven') {
          sh 'mvn test'
       }
     }
  }`

}

The pod.yaml Pod template has different containers , here its definition:

apiVersion: v1
kind: Pod metadata:  
labels: some-label: jenkins-build-agent-maven spec:  
containers:  
-name: maven  
 image: docker.artifactory.serv.cdc.fr/maven-ci:3.8.4-jdk-17  
 imagePullPolicy: Always  
-name: docker-daemon  
 image: docker.artifactory.serv.cdc.fr/docker:20.10.17-dind  
volumeMounts:  
-name: docker-socket  
 mountPath: /var/run

The problem that I have is that I want to run testContainers that require docker runtime with maven, Maven is availible in container('maven') and docker runtime is availible in container('docker-daemon'), If I use container('maven') I get docker runtime not found error and If I use container('docker-daemon') I don't have maven to run tests.

I want to run the tests using jenkinsfile as showed above? is there any way to achieve this ?

Thanks


Solution

  • no need to use separate container for running docker just attach /var/run to maven-ci and everything should work