-1

I have created a jenkins file that above everything else that is does, in the end will copy paste a .jar file from the jenkins target directory to home directory. I tried many options like sudo cp and sudo visudo to give jenkins privilleges but that didn't work, besides it's not safe from security perspective.

Then I tried to install the FileOperations plugin.

stage("Copy the created .jar file to home directory for docker deployment"){
    steps{
    fileOperations([fileCopyOperation(
                        flattenFiles: false,
                        includes: '*.jar',
                        targetLocation: "home/user"
        )])
    }
}

Output:

18:27:37 File Copy Operation:
18:27:37 /var/lib/jenkins/workspace/pipeline_production/my.jar
18:27:37 FATAL: /home/user/my.jar

I quite miss what is going wrong with this configuration and does no succeed. Appreciate any suggestion.

Similar question here

NikSp
  • 1,262
  • 2
  • 19
  • 42

1 Answers1

0

You can check and provide the full path of the jar file where it exists and check if it is available.

 fileOperations([fileCopyOperation(
                        flattenFiles: false,
                        includes: '*.jar',  // Give full path where .jar file exists
                        targetLocation: "home/user"
        )])

Another option could be just use a cp command of shell to copy files :

sh "cp -f <Source path> <Destination>"
sh "cp -f *.jar home/user/"

You could also execute the commands by changing the directory:

    steps{
       dir("<Path of your jar file>"){
               fileOperations([fileCopyOperation(
                        flattenFiles: false,
                        includes: '*.jar',
                        targetLocation: "home/user"
        )])
           OR
        sh "cp -f *.jar home/user/"

        }
    
    }
Altaf
  • 2,838
  • 1
  • 16
  • 8
  • Hey, actually the 'cp' command needs the sudo privileges. So it won't be executed without sudo. Also I tried the option of ```sudo cp``` but this return tty error no response. – NikSp Jun 08 '21 at 12:15
  • @NikSp : Is your jar file available at the location? – Altaf Jun 08 '21 at 13:04
  • Yes it's available on /var/lib/jenkins/workspace/pipeline_production/my.jar as my output states in SO – NikSp Jun 08 '21 at 14:47
  • @NikSp did you try by giving the full path.``includes: "//var//lib//jenkins//workspace//pipeline_production//*.jar",``. You can also execute this in the ``dir("//var//lib//jenkins//workspace//pipeline_production") { fileoperations ..}`` – Altaf Jun 08 '21 at 15:04
  • Yeah but I didn't try it with double slashes ```//```..I used single slashes – NikSp Jun 08 '21 at 15:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/233515/discussion-between-altaf-and-niksp). – Altaf Jun 08 '21 at 15:33