On my Jenkins server, I have a simple test pipeline to check into copying build data to a remote server. I'm using the SSH Pipeline Steps plugin.
My code is:
stage('Remote SSH') {
steps {
sshRemove remote: remote, path: "/mnt/test"
sshCommand remote: remote, command: "mkdir /mnt/test"
writeFile file: './tst/abc.sh', text: 'ls -lrt'
sshPut remote: remote, from: './tst/', into: '/mnt/test/.'
}
The result is that in /mnt/test I have the created "tst" folder and it's contents. What I wanted was just the contents of this tst folder to be transfered to the target.
How should I be formatting the sshPut step?
Looking at source-code and reading a bit about copy commands in Java it seems like this is just the way the filecopy operations work in Java. That one would have to iterate through the directory contents to do it another way.
Since I'm creating the source folder (even in my real build example), it seems that the best option is just to rename the folder before the move:
sshRemove remote: remote, path: "/mnt/test"
writeFile file: './tst/abc.sh', text: 'ls -lrt'
sh "mv ./tst ./test"
sshPut remote: remote, from: './test/.', into: '/mnt/'
I'd happily listen if someone has another solution.
There is an issue about this very use case on Jenkins'Jira https://issues.jenkins-ci.org/browse/JENKINS-58778
I would expect the following to work but it apparently does not:
remote.fileTransfer = 'SCP'
sshPut remote: remote, from: './tst/*', into: '/mnt/test/'
Another way could be to do one sshCommand more after sshPut to 'mv' the files as you please
Usually I Go to https://<myJenkins>/pipeline-syntax and use the step builder. A shame it's not working for sshPut
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With