Skip to content

Commit

Permalink
[DEVO-142] Use a shell copy when archiving files via the Jenkins shar…
Browse files Browse the repository at this point in the history
…ed libraries
  • Loading branch information
Srinivas Bommadevara committed Apr 19, 2021
1 parent a389c24 commit df981c7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/org/hitachivantara/ci/FileUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/org/hitachivantara/ci/archive/ArchivingHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 16 additions & 0 deletions test/src/org/hitachivantara/ci/TestFileUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit df981c7

Please sign in to comment.