ExpediaGroup/jenkins-spock

How to mock docker build process use this frame work

ls1995516 opened this issue · 1 comments

Hi, I tried to use your framework to test Jenkins pipeline shared library which will build a new docker image and push it to the registry.
However, when I tried to run the test file, I was always stuck in the "docker.build()" process., which return a empty docker image.

def docker_image
stage('Build') {
docker_image = docker.build("${params['docker_registry']}:${params['docker_name']}-${version}", "-f ${params['dockerfile_name']} ${params['dockerfile_path']}")
}
docker_image.inside(docker_args) {
xxx some code
}

I tried to test this code.
The error is that the docker_image always return null during the test(it works if I run the code manually). Therefore I am wondering if the problem is that Spock cannot mock the build of docker or which part is wrong for me.

Thank you

Finally, I found out another issue that can change the command to mock the docker.
The way I use to solve the problem is to use another library which can mocked docker in jenkins pipeline