简体   繁体   中英

copy-paste file from jenkins directory to home directory using FileOperations plugin

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

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/"

        }
    
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM