Here is what I am doing and hope to achieve
- I Run docker container.
- Inside container I run the tests.
- And finally I would like to copy the test artifacts out of the container before closing the container.
At the moment I am using it like this and first 2 steps work fine
stage('Pulling Docker Image'){
steps{
echo "Pulling Docker Image"
script{
docker.withRegistry("url", "credentials"){
docker.image(<image>).inside(<arguments>->c{
//run tests inside container
}
}
}
}
}
post{
always{
docker cp <container>:/test_result:/test_result_store/
docker stop <container>
docker rm <container>
}
But with this approach the container is closing and getting removed, before post step is invoked.
I looked at documentation where it mentions run
and withRun
option which returns container handle.
So I modified the code like this
stage('Pulling Docker Image'){
steps{
echo "Pulling Docker Image & Running Tests"
script{
docker.withRegistry("url", "credentials"){
def container_handle = docker.image(<image>).run(<arguments>->c{
//run tests inside container
}
}
}
}
}
post{
always{
docker cp container_handle:/test_result:/test_result_store/
docker stop container_handle
docker rm container_handle
}
but here container_handle
seems to be invalid reference inside post
step, also test is not run inside the container.
I would appreciate if one can point out to obvious errors I am doing here.
Also I am planning to save all this to a pipeline script so let me know, if these steps will work as is or some change might be needed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…