使用 Jenkins 管道解压缩文件
unzip a file using Jenkins pipeline
我有一个名为 ***.zip 的 zip 文件。我使用下面的命令来解压缩它。一旦我解压,里面的文件也是"Zip"个文件(超过3个zip文件)。你能告诉我如何解压缩这些文件吗?
unzip zipFile: "$project_version",dir:"D:\jenkins\DEV\extract\project", quiet: true
正在努力-
unzip dir: 'D:\jenkins\DEV\extract\project', glob: '', zipFile: 'D:\jenkins\DEV\extract\project\project_*.zip'
错误日志
java.io.IOException: D:\jenkins\DEV\extract\project\project_*.zip does not exist.
at org.jenkinsci.plugins.pipeline.utility.steps.zip.UnZipStepExecution.run(UnZipStepExecution.java:77)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:260)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
解压主 zip 文件后我的目录下的文件。
05/16/2018 04:31 PM <DIR> .
05/16/2018 04:31 PM <DIR> ..
05/15/2018 12:51 PM 265,637 project-project1_1.0.0.24_bdd86e0c.zip
05/15/2018 12:51 PM 7,924,188 project-project2_1.4.0.130_43dce5e4.zip
05/15/2018 12:51 PM 6,862,842 project-project3_1.0.0.207_c7d5d471.zip
3 File(s) 15,052,667 bytes
2 Dir(s) 432,451,330,048 bytes free
我在 windows-
中需要类似的命令
for file in `ls 123_*.zip'; do unzip $file -d `echo $file | cut -d "." -f 1`; done
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
Unzip "C:\Temp\Powershell\Test.zip" "C:\Temp\Powershell\"
$DirName = Get-ChildItem "C:\Temp\Powershell\Test"
foreach ( $item in $DirName){
Unzip "C:\Temp\Powershell\Test$item" "C:\Temp\Powershell\Test\"
}
bat 'for /R . %I in ("*.zip") do ( "C:\Program Files\7-Zip\7z.exe" x -y -o"%~dpnI" "%~fI" )'
我们可以在 Jenkins 管道脚本下使用它来实现上述要求
您可以在步骤块中使用管道实用程序步骤
应该同时使用脚本化和声明式管道
steps {
unzip zipFile: 'file.zip', dir: '<directory>'
}
我有一个名为 ***.zip 的 zip 文件。我使用下面的命令来解压缩它。一旦我解压,里面的文件也是"Zip"个文件(超过3个zip文件)。你能告诉我如何解压缩这些文件吗?
unzip zipFile: "$project_version",dir:"D:\jenkins\DEV\extract\project", quiet: true
正在努力-
unzip dir: 'D:\jenkins\DEV\extract\project', glob: '', zipFile: 'D:\jenkins\DEV\extract\project\project_*.zip'
错误日志
java.io.IOException: D:\jenkins\DEV\extract\project\project_*.zip does not exist.
at org.jenkinsci.plugins.pipeline.utility.steps.zip.UnZipStepExecution.run(UnZipStepExecution.java:77)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:260)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution.run(AbstractSynchronousNonBlockingStepExecution.java:44)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
解压主 zip 文件后我的目录下的文件。
05/16/2018 04:31 PM <DIR> .
05/16/2018 04:31 PM <DIR> ..
05/15/2018 12:51 PM 265,637 project-project1_1.0.0.24_bdd86e0c.zip
05/15/2018 12:51 PM 7,924,188 project-project2_1.4.0.130_43dce5e4.zip
05/15/2018 12:51 PM 6,862,842 project-project3_1.0.0.207_c7d5d471.zip
3 File(s) 15,052,667 bytes
2 Dir(s) 432,451,330,048 bytes free
我在 windows-
中需要类似的命令for file in `ls 123_*.zip'; do unzip $file -d `echo $file | cut -d "." -f 1`; done
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
Unzip "C:\Temp\Powershell\Test.zip" "C:\Temp\Powershell\"
$DirName = Get-ChildItem "C:\Temp\Powershell\Test"
foreach ( $item in $DirName){
Unzip "C:\Temp\Powershell\Test$item" "C:\Temp\Powershell\Test\"
}
bat 'for /R . %I in ("*.zip") do ( "C:\Program Files\7-Zip\7z.exe" x -y -o"%~dpnI" "%~fI" )'
我们可以在 Jenkins 管道脚本下使用它来实现上述要求
您可以在步骤块中使用管道实用程序步骤 应该同时使用脚本化和声明式管道
steps {
unzip zipFile: 'file.zip', dir: '<directory>'
}