diff --git a/src/org/hitachivantara/ci/FileUtils.groovy b/src/org/hitachivantara/ci/FileUtils.groovy index c27e8e2..fa25b3b 100644 --- a/src/org/hitachivantara/ci/FileUtils.groovy +++ b/src/org/hitachivantara/ci/FileUtils.groovy @@ -124,6 +124,21 @@ class FileUtils { sourcePath.copyTo(targetPath) } + /** + * Copy files between two locations using sh. + * If this file already exists, it will be overwritten. + * If the directory doesn't exist, it will be created. + * @param source + * @param target + */ + static void shellCopy(def source, def target) { + FilePath sourcePath = create(source) + FilePath targetPath = create(target) + steps.sh "cp -fR ${sourcePath} ${targetPath}" + // steps.log.info "Copied ${sourcePath} to ${targetPath} using shell" + } + + /** * Copies this file to the specified target on master node. * @param src diff --git a/src/org/hitachivantara/ci/archive/ArchivingHelper.groovy b/src/org/hitachivantara/ci/archive/ArchivingHelper.groovy index d688c7a..d57331d 100644 --- a/src/org/hitachivantara/ci/archive/ArchivingHelper.groovy +++ b/src/org/hitachivantara/ci/archive/ArchivingHelper.groovy @@ -202,7 +202,7 @@ Archiving artifacts by copying them to '${targetFolder}': } artifacts.each { String archiveFileName, FilePath file -> - FileUtils.copy(file, FileUtils.create(Paths.get(targetFolder, archiveFileName) as String)) + FileUtils.shellCopy(file, FileUtils.create(Paths.get(targetFolder, archiveFileName) as String)) } if (buildData.isSet(ARCHIVE_TO_JENKINS_MASTER) && buildData.isMinion()) { diff --git a/test/src/org/hitachivantara/ci/TestFileUtils.groovy b/test/src/org/hitachivantara/ci/TestFileUtils.groovy index 72fb36d..13a67f3 100644 --- a/test/src/org/hitachivantara/ci/TestFileUtils.groovy +++ b/test/src/org/hitachivantara/ci/TestFileUtils.groovy @@ -77,6 +77,22 @@ class TestFileUtils extends BasePipelineSpecification { 'target/version.properties' || true // a 2nd time to guarantee that the file gets replaced } + def "test shell file copy"() { + given: + registerAllowedMethod('isUnix', [], { -> true }) + when: + File sourcefile = new File('test/resources/archive/version.properties') + File targetFile = new File('target/version.properties') + FileUtils.shellCopy(sourcefile, targetFile) + then: + targetFile.exists() == exists + + where: + targetFilePath || exists + 'target/version.properties' || true + 'target/version.properties' || true // a 2nd time to guarantee that the file gets replaced + } + def "test find files"() { expect: FileUtils.findFiles('test/resources/archive', "regex:${pattern}", excludes).size() == filesFound