The problem is that the temporary files are created in the default container. This is clearly visible with such a pipeline
podTemplate(cloud: 'kubernetes', yaml: someYamlDefiningASecondContainer) {
node(POD_LABEL) {
sh 'echo "/tmp in default container:" && ls -al /tmp'
container('second-container') {
try {
dir('/tmp/foo') {
sh 'echo ". in container(second-container)/dir(tmp/foo):" && ls -al .'
}
}
catch (e) {
echo "-> exception: $e"
}
sh 'echo "/tmp in container(second-container):" && ls -al /tmp'
}
sh 'echo "/tmp in default container:" && ls -al /tmp'
}
}
The output shows the /tmp/foo@tmp dir created in the default container rather than in the secondOne.
+ echo /tmp in default container:
/tmp in default container:
+ ls -al /tmp
total 16
drwxrwxrwt 1 root root 4096 Jul 19 16:13 .
drwxr-xr-x 1 root root 4096 Jul 19 16:13 ..
drwxr-xr-x 2 jenkins jenkins 4096 Jul 19 16:13 hsperfdata_jenkins
drwxr-xr-x 1 root root 4096 Jul 4 09:27 hsperfdata_root
[Pipeline] container
[Pipeline] {
[Pipeline] dir
Running in /tmp/foo
[Pipeline] {
[Pipeline] sh
process apparently never started in /tmp/foo@tmp/durable-44033be5
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
[Pipeline] [Pipeline] echo
-> exception: hudson.AbortException: script returned exit code -2
[Pipeline] sh
+ echo /tmp in container(second-container):
/tmp in container(second-container):
+ ls -al /tmp
total 16
drwxrwxrwt 1 root root 4096 Jul 19 04:35 .
drwxr-xr-x 1 root root 4096 Jul 19 16:13 ..
drwxr-xr-x 2 jenkins jenkins 4096 Jul 19 04:35 hsperfdata_jenkins
drwxr-xr-x 1 root root 4096 Jul 4 09:27 hsperfdata_root
[Pipeline] }
[Pipeline] [Pipeline] sh
+ echo /tmp in default container:
/tmp in default container:
+ ls -al /tmp
total 24
drwxrwxrwt 1 root root 4096 Jul 19 16:13 .
drwxr-xr-x 1 root root 4096 Jul 19 16:13 ..
drwxr-xr-x 2 jenkins jenkins 4096 Jul 19 16:13 foo
drwxr-xr-x 2 jenkins jenkins 4096 Jul 19 16:18 foo@tmp
drwxr-xr-x 2 jenkins jenkins 4096 Jul 19 16:13 hsperfdata_jenkins
drwxr-xr-x 1 root root 4096 Jul 4 09:27 hsperfdata_root
Looking a bit at the sources, it seems to me that the cause of the problem is that hudson.FilePath used in org.jenkinsci.plugins.workflow.steps.PushdStep holds information about the agent but not about the container causing org.jenkinsci.plugins.durabletask.BourneShellScript to create its temporary files at the wrong place and consequently not able to execute the script.
The problem is that the temporary files are created in the default container. This is clearly visible with such a pipeline
The output shows the /tmp/foo@tmp dir created in the default container rather than in the secondOne.
Looking a bit at the sources, it seems to me that the cause of the problem is that hudson.FilePath used in org.jenkinsci.plugins.workflow.steps.PushdStep holds information about the agent but not about the container causing org.jenkinsci.plugins.durabletask.BourneShellScript to create its temporary files at the wrong place and consequently not able to execute the script.