groovyjenkins-pipelineantbuilder

AntBuilder : Warning: Could not find file to copy


In this Jenkinsfile, I want to copy the list of changed files in GitHub to a new directory /toucd, and then upload them to UCD.

I don't know why the AntBuilder is giving me the above error" Could not find file to copy". Please help.

  stage("list-workspace") {
            steps {
                sh """                    
                    tree ${env.WORKSPACE}
                """
            }
        }

        stage("search-changes") {
            steps {
                script {                    
                    def allChangeFiles = getAllChangeFiles()
                    if (allChangeFiles.isEmpty()) {
                        echo "No changed file"
                        exit 1
                    } 
                    echo "Consolidated all changed files:"
                    allChangeFiles.each {
                        println "# ${it}"
                    }                 
                 
                    String sourceDir = "${env.WORKSPACE}//"
                    String targetDir = "${env.WORKSPACE}//toucd//"
                    def ant = new AntBuilder()
                    allChangeFiles.each {
                        if (it.endsWith(".xml") || it.endsWith(".bprelease")) { 
                            ant.copy( file:"${sourceDir}${it}", tofile:"${targetDir}${it}")
                            println "${it} copied"
                        }
                    }
                } // script
            } // steps
        } //stage("search-changes")  

Output:

 > git rev-list --no-walk a836e45cff6d96d294c89e05d5d3aa6719227b70 # timeout=10
14:17:25  + tree /home/jenkins/workspace/BluePrism/Get-Change-List
14:17:25  /home/jenkins/workspace/BluePrism/Get-Change-List
14:17:25  |-- EventAuditPush.sh
14:17:25  |-- GetChangeList_Jenkinsfile
14:17:25  |-- Object
14:17:25  |   `-- BPA\ Object\ -\ DevOpsSampleObject1.xml
14:17:25  |-- Process
14:17:25  |   `-- BPA\ Process\ -\ DevOpsSampleProcess1.xml
14:17:25  |-- README.md
14:17:25  `-- Release
14:17:25      |-- Release1.1.bprelease
14:17:25      `-- Release1.2.bprelease
14:17:25  
14:17:25  3 directories, 7 files
14:17:26  [Pipeline] }
14:17:26  [Pipeline] // stage


14:17:28  : Warning: Could not find file /home/jenkins/workspace/BluePrism/Get-Change-List/Release/Release1.2.bprelease to copy.
14:17:28    at org.apache.tools.ant.taskdefs.Copy.copySingleFile(Copy.java:639)

Solution

  • I faced the same kind of issue but resolved it with using shell command instead of groovy. I tried many ways to copy file using groovy but none of them worked.

    sh """
    cp ${sourceDir}${it} ${targetDir}${it}
    """