copy folder from one location to another location through jenkins.instance groovy script

please suggest me a script for how to copy job folder to another location, I have tried below  one, but it is not working due to copy method is available for the library


stage('Copy') {
def log = "$Source_Path"
def folderName = log.substring(log.lastIndexOf("/") + 1, log.length())
println "$folderName"
def Archival_Path_folder=Archival_Path+"/"+folderName
println ("$Archival_Path_folder = merged")
def jenkins = Jenkins.instance
def folder = jenkins.getItemByFullName(Archival_Path)
if (folder == null) {
println "ERROR: Folder '$Archival_Path' not found"
else {
println "Folder found $folder"
// Get the all Folders
jenkins.getAllItems().findAll { it.fullName == "${Source_Path}" }.each { folder1 ->
if (folder1.fullName == "$Archival_Path_folder") {
println "folder is already there in the same folder"
} else{
println "Moving '$folder1.name' to '$folder.name'"
Items.move(folder1, folder)

1 comment

  • 0
    Denys Digtiar

    Hi Rameshmari,

    The Jenkins Pipeline is a DSL for defining Continuous Delivery pipelines. It is not designed for maintenance tasks. 

    The feature that is designed for this task is the Jenkins Script Console.

Please sign in to leave a comment.