[英]Jenkins Pipeline Utility Steps - zip zipFile
I am trying to zip the folders which are created as output of my jenkins pipeline job using pipeline script.我正在尝试使用管道脚本压缩作为 jenkins 管道作业输出创建的文件夹。 By googling i came to know the Jenkins
通过谷歌搜索,我开始了解詹金斯
Pipeline Utility Steps - zip zipFile
管道实用程序步骤 - 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. https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-zip-code-create-zip-file压缩文件夹/文件,但无法获得压缩的确切管道语法。
In my job workspace, I have a folder by name 'Test' which has 2 sub folders as 'Test1', 'Test2'.在我的工作工作区中,我有一个名为“Test”的文件夹,它有 2 个子文件夹,分别为“Test1”、“Test2”。 Each sub folder will have .dll files.
每个子文件夹都有 .dll 文件。 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:以下是 Jenkins 的控制台输出:
Started by user XXXXX
[Pipeline] node
Running on Jenkinks_1 in C:\workspace\Build_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我想压缩一些文件作为我的 jenkins 管道作业的输出
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 usesarchiveArtifacts
to record the result.它使用
archiveArtifacts
来记录结果。
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 .正如OP Sri所见,
zip zipFile
是JENKINS Pipeline Utility Steps Plugin 的一部分,并且需要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"...关于用于多标准文件选择的语法, NicolasW 在评论中指出 文档含糊不清:“使用 glob ant-style 语法”...
He got it to work though, with a basic coma separated syntax.尽管如此,他还是使用基本的昏迷分隔语法让它工作了。
Eg例如
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:但是,正如Tanvir在评论中所指出的,问题 44078意味着您需要将
zip
替换为:
script{ zip zipFile: 'test.zip', archive: false, dir: 'archive' }
Meaning you need to use a script
block.这意味着您需要使用
script
块。
安装Pipeline Utility Steps
插件后能够进行压缩。
I came across this because zip was ... not installed on the host.我遇到这个是因为 zip ……没有安装在主机上。
Reminder to self : If you need zip, install it first.提醒自己:如果您需要zip,请先安装它。
sudo yum install zip
you can just use sh (jenkins server need install zip);你可以只使用 sh (jenkins 服务器需要安装 zip);
sh '''
zip -r algo.zip algo
'''
pipeline script like this像这样的管道脚本
node {
stage('Clean'){
cleanWs()
}
stage('Checkout') {
git branch: 'develop', url: 'ssh://user@ip:29418/prj.git'
}
stage('Zip') {
dir('algo-python') {
sh '''
zip -r algo.zip algo
'''
}
}
stage('Upload zip'){
dir('algo-python') {
sh '''
source /etc/profile
export HADOOP_USER_NAME=dev
hdfs dfs -put -f algo.zip /user/dev/zipfile/
'''
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.