jenkinsci / jenkinsci/workflow-basic-steps-plugin
[JENKINS-54110] Pipeline's dir() does not work with symlinks
- Dominant language
- Java
- Stars
- 73
- Forks
- 129
- PR merge metrics
- No merged PRs in 30d
Description
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
---
Originally reported by
monitorjbl, imported from: Pipeline's dir() does not work with symlinks
Raw content of original issue
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
Contributor guide
Assessment
This issue has not been assessed yet.