Question on enviroment in pipeline build with Docker

已查看 10 次
跳至第一个未读帖子

Brett Bergquist

未读,
2020年3月27日 09:44:332020/3/27
收件人 Jenkins Users
I have a pipeline build and steps are using a docker image. A test stage

        stage('Build') {
            agent {
                docker { 
                    image 'git.everest.canoga.com:5005/software-development/devops/docker-test:latest'
                    args '-t'
                }                
            }
            steps {
		sh 'ls -al'
                sh './shellscript.sh'
            }

The docker image has an "entrypoint" that sources in a script to setup for a cross compiler (yocto environment script). I can use this image outside of Jenkins with no issue to run make, compilation, etc. as the environment is setup correctly by the entrypoint sourcing the script. This docker image is based off
with some slight modifications. 

When I try to use this docker image in Jenkins to perform a build, the environment is not setup. Jenkins starts a detached container that stays running in the background from the image and then uses what I assume to be "docker exec" equivalent to execute the steps in the container. Unfortunately when done this way, the environment that was setup by the "entrypoint" is not in effect. 

The environment that is setup through sourcing the yocto environment script is not easily replicated by using the ENV command of the Dockerfile and it changes depending on yocto build and will become maintenance issue if I try to do so. So my question is, is there some way to get this environment script sourced so that the pipeline steps will have the environment that I don't know about? A second question, is the "sh './shellscript.sh' above actually doing something like

docker exec -t <container> sh -c ./shellscript.sh

Or is it doing

docker exec -t <container> ./shellscript.sh

I believe Jenkins is using docker in this fashion to start the container once for the duration of the stage and then execute the steps using the "docker exec" but this really does have an issue with it bypassing the carefully constructed "entrypoint" that might exist for the image.

Any help will be greatly appreciated.
回复全部
回复作者
转发
0 个新帖子