Zip a directory in Jenkins Pipeline

10,372

Try this:

pipeline {
   agent any
   stages {
       stage("test.."){
          steps{
             script{
                    zip archive: true, dir: '', glob: '', zipFile: 'testz.zip'
             }
          }
       }
    }
}

Reference: https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#zip-create-zip-file

Share:
10,372
Idothisallday
Author by

Idothisallday

Updated on June 04, 2022

Comments

  • Idothisallday
    Idothisallday almost 2 years

    I keep getting this error: "No signature of method: zip.call()"

    This is the code i am running in Jenkins pipeline :

    pipeline {
       agent any
       stages {
           stage("test..")
           {
                steps
                {
                 zip dir: '', glob: '', zipFile: 'testz.zip'
                }
            }
        }
    }
    

    I have the zip step appear in sample steps in pipeline syntax, so not sure why this failing. I need to zip my source code folder.

    Pipeline Utility Steps plugins is installed : enter image description here

    • tim_yates
      tim_yates almost 6 years
      Have you installed the "pipeline utility steps" plugin? stackoverflow.com/a/48386777/6509
    • Idothisallday
      Idothisallday almost 6 years
      Yes, added image above
  • raviTeja
    raviTeja almost 2 years
    Does this work when we run a pipeline using a container ?