Skip to content

Commit

Permalink
Made it possible to copy files
Browse files Browse the repository at this point in the history
  • Loading branch information
timrademaker committed Jan 20, 2021
1 parent 70f9ac2 commit b644c2c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions vars/file.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,34 @@ def delete(String path) {
}
}

def copy(String fromPath, String toPath, Boolean force = false, Boolean recurse = true) {
if(nameExists(fromPath)) {
powershell(label: 'Copy item', returnStdout: false, script: "Copy-Item -Path '${fromPath}' -Destination '${toPath}' ${recurse ? '-Recurse' : ''} ${force ? '-Force' : ''}");
}
else {
log.error("Tried to copy '${fromPath}', but this path couldn't be found!");
}
}

def zip(String pathToCompress, String destinationPath, Boolean optimalCompression = true) {
assert(nameExists(pathToCompress));
if(!nameExists(pathToCompress)) {
log.error("Unable to zip ${pathToCompress} as the path can't be found");
return;
}

compressionLevel = optimalCompression ? '[System.IO.Compression.CompressionLevel]::Optimal' : '[System.IO.Compression.CompressionLevel]::Fastest';

powershell(label: "Zip '${pathToCompress}''", script: """Add-Type -AssemblyName System.IO.Compression.FileSystem
powershell(label: "Zip '${pathToCompress}'", script: """Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory('${pathToCompress}', '${destinationPath}', ${compressionLevel}, \$false)""");
}

def unzip(String zipFile, String destinationPath) {
assert(exists(zipFile));
if(!exists(zipFile)) {
log.error("Unable to unzip ${zipFile} as the archive can't be found");
return;
}

powershell(label: "Unzip '${zipFile}''", script: """Add-Type -AssemblyName System.IO.Compression.FileSystem
powershell(label: "Unzip '${zipFile}'", script: """Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory('${zipFile}', '${destinationPath}')""");
}

Expand Down

0 comments on commit b644c2c

Please sign in to comment.