24

I want to transfer files from my post build Jenkins workspace to a location on a remote server. Build goes smoothly for all steps in the job but always transfers 0 files.

This is the console output:

    Started by user Patrick
    Building in workspace /var/lib/jenkins/jobs/20eyes Build/workspace
    Fetching changes from the remote Git repository
    Fetching upstream changes from https://github.com/project/project.git
    using .gitcredentials to set credentials
    Checking out Revision a758e0f8e534271b999a2fc8696b6fd5a3d5e500 (origin/master)
    executing script:

    cd /var/www/20eyes-web
    [SSH] exit-status: 0
    SSH: Connecting from host [dev1.remotehost]
    SSH: Connecting with configuration [dev2.remotehost] ...
    SSH: Disconnecting configuration [dev2.remotehost] ...
    SSH: Transferred 0 file(s)
    Build step 'Send files or execute commands over SSH' changed build result to  SUCCESS
    Finished: SUCCESS

The job is configured to build after any commit is pushed to GitHub

The transfer set is: Source Files:

/var/lib/jenkins/jobs/20eyes Build/workspace/**/*

Remove prefix:

/var/lib/jenkins/jobs/20eyes Build/workspace
whitepatrick
  • 251
  • 1
  • 2
  • 9

6 Answers6

30

I thinks, problem at your config. We have 2 positions to configure.

  1. At System configuration (Global config). --> If test ok ==> Configuration to remote server is ok.
  2. At your project. We will focus about transfer set: (Source file, Remove prefix, remote directory)

    2.1 Source file : if it's blank = workspace directory. in your case i think you should input **/*
    2.2 Remove prefix : refer Here for more info.
    2.3 Remote directory: if it's blank = directory that is configured at System configuration above.

Hope it help! Sorry about my English.

Slav
  • 27,057
  • 11
  • 80
  • 104
PhungLe
  • 352
  • 3
  • 6
  • 4
    This took care of it, in particular 2.1. Thanks! – whitepatrick Aug 13 '14 at 14:16
  • I'm trying to copy files which are not in my workspace (from /var/www/ to destination VM), but I always get `SSH: Transferred 0 file(s)` I tried many variants of `/var/www/mysite` for the source file, prefixing with \*\*/, or suffixing with /\*, /\*\* or /\*/\*\*... nothing seems to work. What m I doing wrong ? – Balmipour Jun 07 '16 at 13:24
  • @Balmipour Have you found a way to get to the parent directory of your current job workspace? – Bruno Bieri Nov 23 '16 at 12:51
  • 1
    @Bruno I just created a symlink in the project, which somehow "fixed" the issue, but is hacky & dirty. Note that renaming the project would change the directory used by Jenkins to a new one, which won't contain the link. I'd love a better solution :) – Balmipour Nov 23 '16 at 15:25
  • @Balmipour ok thank you symlink would in fact work. Yes, it's hacky and not a smooth solution. I think the plugins use case is another one then we intend it to use. – Bruno Bieri Nov 24 '16 at 07:13
  • I have a file in workspace folder named `hello-world.tar.gz` My server connection is good. getting SSH: Transferred 0 file(s) how do i solve this problem? – mizan3008 Apr 02 '17 at 12:34
  • I see this answer is quite old but it helped solve my problem. Thank you. – John Jul 09 '19 at 14:47
  • For me works with *.zip But doesn't work with specific file. – Zaha Apr 22 '20 at 04:17
10

Quick thing to try first: set the Source folder only with: **/* to see if any file is copied. If file was copied then take a look here to see how to write the correct path here

Popa Andrei
  • 2,299
  • 21
  • 25
5

My advices:

  1. You should avoid using spaces in the Jenkins job name!
    • in your case: name 20eyes Build can produce some troubles in file/directory matching
  2. You should use relative paths and not absolute paths!
    • in your case: /var/lib/jenkins/... should be replaced by relative path from job's workspace
  3. You should NOT copy whole workspace!
    • specify only appropriate files from last build (e.g. WAR file from target directory)
  4. You should check documentation and examples of Publish Over plugins:
lu_ko
  • 4,055
  • 2
  • 26
  • 31
1

In my case I was using the absolute path(from root) in "Transfer Set Source Files:". When I changed the path relative to the workspace, It worked!

Shashi Ranjan
  • 1,491
  • 6
  • 27
  • 52
0

Another common mistake with sourceFiles

This will NOT work:

  • sourceFiles: '/path/dir/**'
  • sourceFiles: '../dir/**'
  • and even sourceFiles: './dir/**' !

While this WILL:

  • sourceFiles: 'dir/**'

Behaviour explained in plugin docs: sourceFiles is a string, comma separated list of includes for an Ant fileset eg. '**/*.jar' (see Patterns in the Ant manual).

Whereas patterns in the Ant manual say:

In general, patterns are considered relative paths, relative to a task dependent base directory (the dir attribute in the case of ). Only files found below that base directory are considered. So while a pattern like ../foo.java is possible, it will not match anything when applied since the base directory's parent is never scanned for files.

0
After Appropriated configuring the SSH server/host in: 

Manage Jenkins >> configure System >> SSH Server

Then you can configure the source file in this format **/*.war or **/*.jar as the case may be.


The remote directory in this format: //opt//copyfolder

Refer the image below for reference:

enter image description here

Damilola Abioye
  • 191
  • 1
  • 5