Stash and Unstash in jenkins declarative pipeline
The include paths provided to the stash command must be relative to the working directory (which is normally the workspace). Jenkins treats them as relative paths even if they start with /
. You can, however, stash from an arbitrary location by wrapping the stash directive in a dir
:
dir( '/root' ) {
stash includes: 'hello-world', name: 'mysrc'
}
If you really are stashing from /root
though, your problem might also be that unless you are running Jenkins as root the permissions on /root
probably won't allow you to access that directory, which would explain why you got the error about no files being included in the stash (because nothing got stashed because it wasn't readable).
You can avoid the "nothing got stashed" problem by adding allowEmpty: false
to your stash options, to make it raise an error while stashing if no files were found, rather than raising it while unstashing.