0

在这个 Jenkinsfile 中,我想将 GitHub 中更改的文件列表复制到一个新目录 /toucd,然后将它们上传到 UCD。

我不知道为什么 AntBuilder 给我上面的错误“找不到要复制的文件”。请帮忙。

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

输出:

 > 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)
4

1 回答 1

0

我遇到了同样的问题,但使用 shell 命令而不是 groovy 解决了它。我尝试了许多使用 groovy 复制文件的方法,但都没有奏效。

sh """
cp ${sourceDir}${it} ${targetDir}${it}
"""
于 2020-08-18T13:04:37.973 回答