Jump to content
groovyPost Forums

Groovy copy files from one directory to another

Recommended Posts

Hi list,

I am trying to use this script to copy a file from one directory to another


def publish() {

echo "Publish artifacts ..."

String sourceFilePath = "%WORKSPACE%\\app\\build\\outputs\\newrelease.tar"

String destinationFilePath = "\\app.xxx.net\\d\$\\Share"

// bat 'copy ${sourceFilePath} ${destinationFilePath}'

(new AntBuilder()).copy(file: sourceFilePath, tofile: destinationFilePath)


I am getting the following error even after approving from "in process script approvals" : 

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new groovy.util.AntBuilder
	at org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.StaticWhitelist.rejectNew(StaticWhitelist.java:184)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onNewInstance(SandboxInterceptor.java:148)


def pipeline () {




If I use bat 'copy ${sourceFilePath} ${destinationFilePath}' I am getting following error:

org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing


Thanks in advance






Link to comment
Share on other sites

I have figured out that actually, I was not using that properly in the Pipeline. I am stuck with another problem, copying files from Workspace on Windows


def deployartifact() {
 echo "Deploy artifacts ..."
 stage('Deploy') {
  node {
    def sourceFilePath = 'outputs\\release\\file.tar'
    def destinationFilePath = '\\\\server.net\\d\$\\Share'
    echo "Sourcefilepath is ${sourceFilePath} and Destinationpath is ${destinationFilePath}"
    bat 'copy %WORKSPACE%\\${sourceFilePath} ${destinationFilePath}'


File is not getting copied because of the WORKSPACE, I tried env.WORKSPACE also.


Thanks in advance

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Who's Online   0 Members, 0 Anonymous, 14 Guests (See full list)

    • There are no registered users currently online
  • Create New...