Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-52493

Declarative: Steps don't run inside container with "dockerfile true"

    Details

    • Similar Issues:

      Description

      Container image is built and executed correctly but step commands run outside container.

      Jenkins 2.121.1 (running as a systemd unit on master and a remote build node through SSH Slave plugin)
      Docker Pipeline plugin 1.17 (released in May 2018)
      Docker CE 18.03 running on CentOS 7.5
       

      pipeline {
          agent { dockerfile true }
          stages {
              stage('Test') {
                  steps {
                      sh 'cd /app && npm test'
                  }
              }
          }
      } 

      And then the test stage doesn't run inside the Docker container that was started:

      [Pipeline] withDockerContainer
      ci-node does not seem to be running inside a container
      $ docker run -t -d -u 1020:1020 -w /home/jenkins/workspace/gpii-express_PR-7-something -v /home/jenkins/workspace/gpii-express_PR-7-something:/home/jenkins/workspace/gpii-express_PR-7-something:rw,z -v /home/jenkins/workspace/gpii-express_PR-7-something@tmp:/home/jenkins/workspace/gpii-express_PR-7-something@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** 1d0c4aca5306042f527e42c2e15dd885f78a0ac3 cat
      $ docker top 9d555195979c311991213dbcc0ef367c66b86972ba8deeb44322b122b2c02c41 -eo pid,comm
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (Test)
      [Pipeline] sh
      [gpii-express_PR-7-something] Running shell script
      + cd /app
      + npm test
      
      > gpii-express@1.0.15 pretest /app
      > node node_modules/rimraf/rimraf coverage/* reports/*
      
      
      > gpii-express@1.0.15 test /app
      > node node_modules/istanbul/lib/cli.js cover tests/all-tests.js --print summary
      
      /app/node_modules/mkdirp/index.js:90
                          throw err0;
                          ^
      
      Error: EACCES: permission denied, mkdir '/app/reports'
          at Object.mkdirSync (fs.js:738:3)
          at Function.sync (/app/node_modules/mkdirp/index.js:71:13)
          at Object.run (/app/node_modules/istanbul/lib/command/common/run-with-cover.js:129:16)
          at CoverCommand.run (/app/node_modules/istanbul/lib/command/cover.js:27:22)
          at runCommand (/app/node_modules/istanbul/lib/cli.js:83:19)
          at runToCompletion (/app/node_modules/istanbul/lib/cli.js:87:5)
          at Object.<anonymous> (/app/node_modules/istanbul/lib/cli.js:93:5)
          at Module._compile (internal/modules/cjs/loader.js:702:30)
          at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
          at Module.load (internal/modules/cjs/loader.js:612:32)
      npm ERR! Test failed.  See above for more details.
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      $ docker stop --time=1 9d555195979c311991213dbcc0ef367c66b86972ba8deeb44322b122b2c02c41
      $ docker rm -f 9d555195979c311991213dbcc0ef367c66b86972ba8deeb44322b122b2c02c41
      [Pipeline] // withDockerContainer
      [Pipeline] }
      [Pipeline] // withEnv
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      

      Running the Docker image that Jenkins built works just fine:

      $ docker run --rm -ti 1d0c4aca5306042f527e42c2e15dd885f78a0ac3 /bin/sh
      /app $ npm test
      
      > gpii-express@1.0.15 pretest /app
      > node node_modules/rimraf/rimraf coverage/* reports/*
      
      
      > gpii-express@1.0.15 test /app
      > node node_modules/istanbul/lib/cli.js cover tests/all-tests.js --print summary
      ...
      16:53:58.388:  jq: ***************
      16:53:58.388:  jq: All tests concluded: 167/167 total passed in 15718ms - PASS
      16:53:58.389:  jq: ***************
      /app $ exit
      

        Attachments

          Issue Links

            Activity

            Hide
            gtirloni Giovanni Tirloni added a comment -

            Jenkinsfile taking from official documentation: https://jenkins.io/doc/book/pipeline/docker/#dockerfile

            Show
            gtirloni Giovanni Tirloni added a comment - Jenkinsfile taking from official documentation: https://jenkins.io/doc/book/pipeline/docker/#dockerfile
            Hide
            reinoutvanrees Reinout van Rees added a comment -

            Same here with a similar Jenkinsfile.

            I even tried placing the `agent { dockerfile true }` line inside the stage, but it still isn't getting used.

            To debug the issue, I placed a `sh pwd` in the stage, which prints the current working directory: `/var/lib/jenkins/jobs/nens/jobs/cookiecutter-staticsite-template/branches/master/workspace`, so it is indeed just running from the workspace, not from within the docker.

             

            Show
            reinoutvanrees Reinout van Rees added a comment - Same here with a similar Jenkinsfile. I even tried placing the `agent { dockerfile true }` line inside the stage, but it still isn't getting used. To debug the issue, I placed a `sh pwd` in the stage, which prints the current working directory: `/var/lib/jenkins/jobs/nens/jobs/cookiecutter-staticsite-template/branches/master/workspace`, so it is indeed just running from the workspace, not from within the docker.  
            Hide
            amcsi Attila Szeremi added a comment - - edited

            I'm getting pretty much the same issue, but with trying to run PHP tests rather than node ones.

            Although for me it says "Jenkins seems to be running inside container" (which is true).

            Any solutions?

            Show
            amcsi Attila Szeremi added a comment - - edited I'm getting pretty much the same issue, but with trying to run PHP tests rather than node ones. Although for me it says "Jenkins seems to be running inside container" (which is true). Any solutions?
            Hide
            amcsi Attila Szeremi added a comment -

            And I'm getting the same issue even if I'm running Jenkins outside of a container, and on my host.

            Show
            amcsi Attila Szeremi added a comment - And I'm getting the same issue even if I'm running Jenkins outside of a container, and on my host.

              People

              • Assignee:
                Unassigned
                Reporter:
                gtirloni Giovanni Tirloni
              • Votes:
                2 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: