Sign in to follow this  
RogerG

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 () {

buildStage()

pubish()

}

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

 

 

 

 

 

Share this post


Link to post
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
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

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

    There are no registered users currently online