Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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:\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

like image 946
Sri Avatar asked Jan 20 '18 03:01

Sri


People also ask

What are the 3 types of pipelines in Jenkins?

Different Types of Jenkins CI/CD Pipelines. Scripted Pipeline. Declarative Pipeline.

What are three important stages in Jenkins pipeline?

Stage. A stage block defines a conceptually distinct subset of tasks performed through the entire Pipeline (e.g. "Build", "Test" and "Deploy" stages), which is used by many plugins to visualize or present Jenkins Pipeline status/progress.


2 Answers

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.

like image 85
VonC Avatar answered Nov 26 '22 12:11

VonC


Was able to Zip after installing the Pipeline Utility Steps plugin.

like image 25
Sri Avatar answered Nov 26 '22 10:11

Sri