Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Jenkins-Pipeline how do I use sshPut to copy contents of folder, not folder itself?

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?

like image 920
Dave Alger Avatar asked Nov 25 '25 05:11

Dave Alger


2 Answers

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.

like image 200
Dave Alger Avatar answered Nov 28 '25 01:11

Dave Alger


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

like image 20
fredericrous Avatar answered Nov 28 '25 01:11

fredericrous