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

dir() step fails with docker agent when API version is prior to 1.35

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • docker, pipeline
    • None

      When using the RedHat Docker distribution, the dir step fails.

      Given this example pipeline :

      pipeline {
          agent {
              docker {
                  image 'alpine'
              }
          }
          stages {
              stage('Test') {
                  steps {
                      dir('test') {
                          sh 'pwd'
                      }
                  }
              }
          }
      }
      

      After a couple of minutes doing nothing in the dir step, the build finally fails with this error :

       

      [Pipeline] dir
      Running in /home/jenkins/agent/workspace/test/test
      [Pipeline] {
      [Pipeline] sh
      process apparently never started in /home/jenkins/agent/workspace/test/test@tmp/durable-e1730f3c
      (running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
      [Pipeline] }
      [Pipeline] // dir
      

      When running Jenkins with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true as suggested, it outputs more info :

       

      [Pipeline] dir
      Running in /home/jenkins/agent/workspace/test/test
      [Pipeline] {
      [Pipeline] sh
      "--workdir" requires API version 1.35, but the Docker daemon API version is 1.26
      process apparently never started in /home/jenkins/agent/workspace/test/test@tmp/durable-af2c36e9
      [Pipeline] }
      [Pipeline] // dir

       

      I guess the dir step has a specific behavior when running on a Docker agent and tries to use --workdir option to change directory. Unfortunately, this option is not available with Docker API < 1.35, which is the case with the RedHat distribution.

      IMHO, the dir step should be agnostic of whether or not the step is running in a Docker agent.

      I didn't find the piece of code that is responsible for this behavior. I would be glad to submit a PR as soon as someone helps me find it.

            csanchez Carlos Sanchez
            ericcitaire Eric Citaire
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: