Jenkins 管道实用程序步骤 - zip zipFile [英] Jenkins Pipeline Utility Steps - zip zipFile
问题描述
我正在尝试使用管道脚本压缩作为我的 jenkins 管道作业的输出创建的文件夹.通过谷歌搜索,我认识了 Jenkins
<块引用>管道实用程序步骤 - zip zipFile
https:///jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-zip-code-create-zip-file 压缩文件夹/文件,但无法获得精确的压缩管道语法.p>
在我的工作工作区中,我有一个名为Test"的文件夹,其中有 2 个子文件夹分别为Test1"和Test2".每个子文件夹都有 .dll 文件.所以,我想用所有子文件夹压缩整个测试"文件夹.
node(Jenkinks_1){回声邮编"zip zipFile: 'Test.zip', 目录:'C:\workspace\Build_Sample\Test'回声结束 - 邮编"}
以下是 Jenkins 的控制台输出:
由用户 XXXXX 发起[管道] 节点在 C:workspaceBuild_Sample 中的 Jenkins_1 上运行[管道] {[管道] 回声压缩[管道] 回声结束 - 邮编[管道] }[管道]//节点[管道] 管道结束完成:成功
寻找一些使用管道语法压缩文件夹的指导.感谢您的投入.
我想压缩一些文件作为我的 jenkins 管道作业的输出
首先,分阶段分步尝试相同的操作,如这里:
管道{代理任何阶段{阶段('推送工件'){脚步 {sh 'mkdir 存档'sh'echo 测试 >存档/test.txt'zip zipFile:'test.zip',存档:假,目录:'存档'archiveArtifacts 工件:'test.zip',指纹:真}}...}
它使用 archiveArtifacts
来记录结果.
如果现在可以使用绝对路径,请尝试使用相对路径 ('..'
)
正如 OP Sri 所见,zip zipFile
是其中的一部分,并且需要JENKINS 管道实用程序步骤插件.
请参阅实施步骤".
关于用于多条件文件选择的语法,NicolasW 注释 在评论中指出 文档含糊不清:使用 glob ant-style 语法"...
不过,他用逗号分隔的基本语法让它工作了.
例如
zip zipFile: 'test.zip', archive: false, glob: 'config-/**/,scripts/**/*.*
但是,正如 Tanvir 所述/jenkins-pipeline-utility-steps-zip-zipfile/48353127?noredirect=1#comment118334240_48353127">评论, issue 44078 表示您需要将 zip
替换为:
script{ zip zipFile: 'test.zip', archive: false, dir: 'archive' }
意味着您需要使用 script
块.
I am trying to zip the folders which are created as output of my jenkins pipeline job using pipeline script. By googling i came to know the Jenkins
Pipeline Utility Steps - zip zipFile
https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-zip-code-create-zip-file to zip folders/files but could not get exact pipeline syntax to zip.
In my job workspace, I have a folder by name 'Test' which has 2 sub folders as 'Test1', 'Test2'. Each sub folder will have .dll files. So, I would like to zip entire 'Test' folder with all subfolder.
node(Jenkinks_1)
{
echo "ZIP"
zip zipFile: 'Test.zip', dir:'C:\workspace\Build_Sample\Test'
echo "END - ZIP"
}
Below are the Console Output from Jenkins:
Started by user XXXXX
[Pipeline] node
Running on Jenkinks_1 in C:workspaceBuild_Sample
[Pipeline] {
[Pipeline] echo
ZIP
[Pipeline] echo
END - ZIP
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Looking for some guidance to zip the folders using pipeline syntax. Appreciate your inputs.
I wanted to zip some files as output of my jenkins pipeline job
First, try the same operation in stages and step, as in here:
pipeline {
agent any
stages {
stage ('push artifact') {
steps {
sh 'mkdir archive'
sh 'echo test > archive/test.txt'
zip zipFile: 'test.zip', archive: false, dir: 'archive'
archiveArtifacts artifacts: 'test.zip', fingerprint: true
}
}
...
}
It uses archiveArtifacts
to record the result.
If using an absolute path does now work, try a relative one ('..'
)
As seen by the OP Sri, zip zipFile
is part of, and requires the JENKINS Pipeline Utility Steps Plugin.
See "Implemented Steps".
Regarding the syntax to be used for multi-criteria file selection, NicolasW notes in the comments that the documentation is vague: "use glob ant-style syntax"...
He got it to work though, with a basic coma separated syntax.
E.g.
zip zipFile: 'test.zip', archive: false, glob: 'config-/**/,scripts/**/*.*
But, as noted by Tanvir in the comments, issue 44078 means you need to replace zip
by:
script{ zip zipFile: 'test.zip', archive: false, dir: 'archive' }
Meaning you need to use a script
block.
这篇关于Jenkins 管道实用程序步骤 - zip zipFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!