I’ve been trying to use the Testcontainers library with my current Jenkins CI/CD pipeline for postgres DB integration tests. I was previously using an embedded postgres library, but now in my jenkins pipeline I do all the steps inside a container, and I wasn’t able to make it work. Then I came across the Testcontainers project which seems to be a pretty good alternative for my Java Spring project.
I’ve been following this article and it states that we most likely don’t have to change anything for CI environmets because testcontainers recognizes that it’s running inside a container and it supports it. Also, in testcontainer’s official documentation there’s this.
So, apparently it’s supposed to work even if we are running the integration tests within a containerized environment, but when I try it I get the following error in my integration tests:
ERROR org.testcontainers.dockerclient.DockerClientProviderStrategy - Could not find a valid Docker environment. Please check configuration.
This is my jenkinsfile (I use PCF)
node('pcf-node') {
container('jdk17-container') {
...
stage('integration testing') {
currentStep = "${env.STAGE_NAME}"
runIntegrationTests()
}
...
}
}
After some research I’m still not sure if docker should be accessible within the container from the jenkins pipeline, but when I run docker info
inside de container it returns docker: command not found
.
Any suggestions to make this work?
2
Answers
Are you sure the machine on which Jenkins is installed is also running the Docker process?
In order to use test-containers, Docker must be installed and running on the machine on which you are running the tests.
The solution is to install and run the Docker process on the CI/CD machine.
For example: try turning off your local instance of Docker and launching testcontainers tests. You will get something like this:
It Seems like , where test code is running docker service is not running on the same machine so this issue is occurred.