Jenkins Pipeline Utility步骤-zip zipFile [英] Jenkins Pipeline Utility Steps - zip zipFile

查看:2035
本文介绍了Jenkins Pipeline Utility步骤-zip zipFile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用流水线脚本压缩作为我的詹金斯流水线作业的输出创建的文件夹.通过谷歌搜索,我认识了詹金斯

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实用程序步骤-zip zipFile

Pipeline Utility Steps - zip zipFile

https: //jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-zip-code-create-zip-file 压缩文件夹/文件,但无法获取确切的管道语法.

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.

在我的工作区中,我有一个名为"Test"的文件夹,其中有2个子文件夹,分别为"Test1","Test2".每个子文件夹将包含.dll文件.因此,我想使用所有子文件夹压缩整个"Test"文件夹.

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"
}

以下是Jenkins的控制台输出:

Below are the Console Output from 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.

我想将一些文件压缩为我的jenkins管道作业的输出

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
            }
        }
        ...
    }

它使用 archiveArtifacts 记录结果.

It uses archiveArtifacts to record the result.

如果现在可以使用绝对路径了,请尝试相对路径('..')

If using an absolute path does now work, try a relative one ('..')

OP Sri 所见,zip zipFile是其中的一部分,并且需要已执行的步骤".

As seen by the OP Sri, zip zipFile is part of, and requires the JENKINS Pipeline Utility Steps Plugin.
See "Implemented Steps".

关于用于多标准文件选择的语法, NicolasW 注意 不过,他使用逗号分隔的基本语法使它起作用.
例如.

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/**/*.*

这篇关于Jenkins Pipeline Utility步骤-zip zipFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆