Copy build artifacts from insider docker to host
Jenkins has some standard support for Docker; this is described in Using Docker with Pipeline in the Jenkins documentation. In particular, Jenkins knows how to use a Docker image that contains just tools, combined with the project's workspace directory. I'd use that support instead of trying to script docker cp
.
That might look roughly like so:
pipeline { agent none stages { stage('Build') { // Jenkins will run `docker build` for you agent { dockerfile { args '--privileged' } } steps { // The current working directory is bind-mounted into the container; // the image's `ENTRYPOINT`/`CMD` is ignored. // Copy the file out of the container: sh "cp /usr/src/myCppProject/build/*.hex ." } } stage('Program') { agent any // so not in Docker steps { sh 'openocd -d0 -f board/st_nucleo_f4.cfg -c "init;targets;halt;flash write_image erase Testbench.hex;shutdown"' } } }}
If you use this approach, also consider whether you should run the main build sequence via Jenkins pipeline steps, or a sh
invocation that runs a shell script, or a Makefile, or if a Dockerfile is actually right. It might make sense to build a Docker image out of your customized compiler, but then use the Jenkins pipeline support to build the image for the target board rather than trying to do it all in a Dockerfile.
In the invocation you show, you can't directly docker cp
a file out of an image. When you start the container, use docker run --name
to give it a name, then docker cp
from that container name.
sh 'docker run --name builder ... my-gcc:1.0'sh 'docker cp builder:/usr/src/myCppProject/build/*.hex .'sh 'docker rm builder'