I am trying to include a single file into a stash in a Jenkins/Cloudbees pipeline. In my understanding, this should work like this:
stage('Stash File') {
steps {
stash includes: 'File.jar', name: 'File'
}
}
However, for some reason it does not, and when it runs in Jenkins, the step fails, but without any error message, like this:
[Pipeline] stage
[Pipeline] { (Stash File)
[Pipeline] node
Running on Jenkins in /var/lib/cloudbees-core-cm/workspace/AutoDeploy/APPS/File/AutoDeploy
[Pipeline] {
[Pipeline] stash
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Copy File to target folder)
Stage "Copy File to target folder" skipped due to earlier failure(s)
I've added an sh "ls -la" to ascertain that the file is in the current folder, and it looks like it is. The output of that command is:
[Pipeline] sh
+ ls -la
total 12
drwxr-xr-x 3 cloudbees-core-cm cloudbees-core-cm 4096 27. Oct 12:46 .
drwxr-xr-x 4 cloudbees-core-cm cloudbees-core-cm 4096 27. Oct 12:46 ..
drwxr-xr-x 2 cloudbees-core-cm cloudbees-core-cm 4096 27. Oct 12:46 File.jar
If I use this syntax instead, it works, and the file is added to the stash on account of this being the only file in the folder:
stash includes: '**', name: 'File'
However, I would really prefer to specify the file I want stashed by name. Is this something that is not possible?
Here's variations of my initial syntax that I've tried, all without success:
stash includes: '**/File.jar', name: 'File'
stash includes: '/File.jar', name: 'File'
stash includes: '.File.jar', name: 'File'
stash includes: '***/File.jar', name: 'File'
stash includes: '*/File.jar', name: 'File'
tl:dr: What am I doing wrong here? What is the correct syntax for including a single file in a stash?
Try using just 'File.jar'. I was having a similar issue and put the file name in in the 'includes' since Jenkins was already in the directory and it worked.