0

I am following the Jenkins tutorial with some modification.

I run the Jenkins docker container by:

docker run --rm --privileged -u root -p 8080:8080 \
 -v /var/run/docker.sock:/var/run/docker.sock \
 -v "$PWD"/vol:/var/jenkins_home \                        
 jenkinsci/blueocean

With my Jenkinsfiles:

    stage('Test') {
        agent {
            docker {
                image 'qnib/pytest'
            }
        }
        steps {
          sh 'ls'                                                                  ##### 1
          sh 'py.test --junit-xml test-reports/results.xml sources/test_calc.py'   ##### 2   
        }
  
    }
    stage('Deliver') {
        agent any
        environment {
            VOLUME = '$(pwd)/sources:/src'
            ABS_WS = '/home/myname/vol/workspace'
            JOB_WS = "\${PWD##*/}"
            IMAGE = 'cdrx/pyinstaller-linux:python2'
        }
        steps {
            dir(path: env.BUILD_ID) {
                unstash(name: 'compiled-results')
                sh "pwd"                                                            ##### 3
                sh "ls"                                                             ##### 4
                sh "docker run -v '${ABS_WS}/${JOB_WS}/sources:/src' ${IMAGE} 'ls'" ##### 5
                sh "docker run -v ${ABS_WS}/${JOB_WS}/sources:/src ${IMAGE} 'ls'"   ##### 6
                sh "docker run -v ${VOLUME} ${IMAGE} 'ls'"                          ##### 7
                
            }
        }
    }

The output and my questions for ####1~6:

####1: ls here including the /sources/*.py that docker container(qnib/pytest) can process.

####3: output: /var/jenkins_home/workspace/simple-python-pyinstaller-app/32

####4: ls here also including the /soucres/*.py we need

####5: ls here didn't include /sources/*.py, due to docker volume mounted failed. I already tried with different solution from here, still not working.

docker run -v '/home/myname/vol/workspace/${PWD##*/}/sources:/src' cdrx/pyinstaller-linux:python2 ls 
bash: cannot set terminal process group (-1): Inappropriate ioctl for device   
bash: no job control in this shell
ls
add2vals.spec  
build
dist

BUT ####6, similar to ####5 just without Single quotation, nothing output from ls (WHY?):

docker run -v /home/myname/vol/workspace/32/sources:/src cdrx/pyinstaller-linux:python2 ls
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
ls

####7. the output is identical to ####5 docker run

 -v /var/jenkins_home/workspace/simple-python-pyinstaller-app/32/sources:/src cdrx/pyinstaller-linux:python2 ls
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
ls
add2vals.spec
build
dist

My questions are:

  1. In Deliver stage, how can I map docker container volume to the host or Jenkins container? In ####3,4 the path in Jenkins container is /var/jenkins_home/workspace/simple-python-pyinstaller-app/32 , this path including the /sources/*.py; and #####7 we can see /var/jenkins_home/workspace/simple-python-pyinstaller-app/32/sources:/src, I thought it was mounted on the correct path to /src in pyinstaller-linux container.

  2. I am not very clear why in Test stage we don't need to mount any volume when running pytest docker? And why not Deliver stage going the same way as Test stage? (like ####2)

  3. What is difference between ####6 and ####5 ?

sobkew36
  • 1
  • 1

0 Answers0