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

Pipeline's dir() does not work with symlinks

XMLWordPrintable

      I'm currently trying to do this as a way of getting around bash's interpreter path length restrictions. Since Jenkins Pipeline generates an obscenely long workspace name, I figured the easiest solution would be to create a symlink in /tmp and just change directory into it. Unfortunately, this does not work.

      This is easy to reproduce, just run the following Pipeline job:

      node {
          def id = UUID.randomUUID().toString()
          def symlink = "/tmp/${id}"
          sh("ln -s ${pwd()} ${symlink}")
          sh("ls -lah /tmp")
          dir(symlink) {
              println("Jenkins thinks we are in ${pwd()}")
              sh('echo "But we are actually in `pwd`"')
              sh("ls -lah /tmp")
          }
          sh("rm -fr /tmp/${id}")
      } 

       

      If you run that, you'll also see that Jenkins generates this odd directory when you try to change into the symlink:

       

      + ls -lah /tmp
      total 3.0M
      drwxrwxrwt 43 root     root     4.0K Oct 16 18:36 .
      dr-xr-xr-x 27 root     root     4.0K Oct 16 18:10 ..
      lrwxrwxrwx  1 jenkins  jenkins    40 Oct 16 18:36 136ef826-e9a1-479e-9074-1de076349252 -> /var/build/workspace/jenkinsfile-sandbox
      drwxr-xr-x  3 jenkins  jenkins  4.0K Oct 16 18:36 136ef826-e9a1-479e-9074-1de076349252@tmp 

       

            Unassigned Unassigned
            monitorjbl Taylor Jones
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: