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

Global Docker agent breaks nested agent usage

XMLWordPrintable

      pipeline {
          agent none
          stages {
              stage('parent stage') {
                  agent {
                      docker {
                          image 'ubuntu:bionic'
                      }
                  }
                  stages {
                      stage('inherited agent') {
                          steps {
                              sh 'uname -a'
                          }
                      }
                      stage('explicit agent') {
                          agent {
                              node {
                                  label 'master'
                              }
                          }
                          steps {
                              sh 'uname -a'
                          }
                      }
                  }
              }
          }
      }
      

      The above pipeline results in the following output:

      Started by user unknown or anonymous
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] Start of Pipeline
      [Pipeline] node
      Running on Jenkins in /var/lib/jenkins/workspace/docker-durable-bug
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (parent stage)
      [Pipeline] getContext
      [Pipeline] isUnix
      [Pipeline] sh
      + docker inspect -f . ubuntu:bionic
      .
      [Pipeline] withDockerContainer
      Jenkins does not seem to be running inside a container
      $ docker run -t -d -u 982:982 -w /var/lib/jenkins/workspace/docker-durable-bug -v /var/lib/jenkins/workspace/docker-durable-bug:/var/lib/jenkins/workspace/docker-durable-bug:rw,z -v /var/lib/jenkins/workspace/docker-durable-bug@tmp:/var/lib/jenkins/workspace/docker-durable-bug@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** ubuntu:bionic cat
      $ docker top c84a4a643ed58929a86d80300821f04249f3e882de21c190043ac475b43eb3f6 -eo pid,comm
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (inherited agent)
      [Pipeline] sh
      + uname -a
      Linux c84a4a643ed5 5.8.1-arch1-1 #1 SMP PREEMPT Wed, 12 Aug 2020 18:50:43 +0000 x86_64 x86_64 x86_64 GNU/Linux
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (explicit agent)
      [Pipeline] node
      Running on Jenkins in /var/lib/jenkins/workspace/docker-durable-bug@2
      [Pipeline] {
      [Pipeline] sh
      process apparently never started in /var/lib/jenkins/workspace/docker-durable-bug@2@tmp/durable-4a02313c
      (running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      $ docker stop --time=1 c84a4a643ed58929a86d80300821f04249f3e882de21c190043ac475b43eb3f6
      $ docker rm -f c84a4a643ed58929a86d80300821f04249f3e882de21c190043ac475b43eb3f6
      [Pipeline] // withDockerContainer
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code -2
      Finished: FAILURE
      

      If I use a regular agent, rather than a docker one, there's no problem.
      The above example works in a clean environment and it is explicitly prepared to reproduce it.

            Unassigned Unassigned
            smirky Bogomil Vasilev
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: