Zip and archive folder/sub folders

6,565 views
Skip to first unread message

Baswaraj Malage

unread,
Mar 8, 2017, 11:52:58 PM3/8/17
to Jenkins Users
Hi Team
I would like to know how to zip and archive folders/subfolders/*.png files in pipeline script.

In my job workspace, I have a folder by name ScreenPrint which has 3 sub folders as chrome, firefox and phantom. Each sub folder would have .png files. So, I would like to zip and archive entire ScreenPrint folder with all subfolder/files to keep them separate for review. I did use below command which archived files but not separated by folders.

archiveArtifacts allowEmptyArchive: true, artifacts: 'screenprint/**', onlyIfSuccessful: true


When I looked @ 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.

zip zipFile: 'screen.zip', glob: '', dir:'', archive: true 


Looking for some guidance to zip the folders using pipeline syntax.

Thanks
Baswaraj

jer...@bodycad.com

unread,
Mar 9, 2017, 2:59:55 PM3/9/17
to Jenkins Users
glob is the ant style syntax to fetch you png files:

zip zipFile: 'screen.zip' archive: true dir: 'screenprint' glob: '**/*.png'

Else you may want to create a folder and copy all the file into it then zip it.

Baswaraj Malage

unread,
Mar 9, 2017, 11:21:31 PM3/9/17
to Jenkins Users

Thank you for your suggestions. However, I got below error on running zip bat command.

zip zipFile: 'screen.zip' archive: true dir: 'screenprint' glob: '**/*.png' 
'zip' is not recognized as an internal or external command,
operable program or batch file. 


-Baswaraj

Jérôme Godbout

unread,
Mar 10, 2017, 9:14:26 AM3/10/17
to jenkins...@googlegroups.com
which version of Jenkins are you using? zip was introduced not so long ago.

Also make sure you call it inside a node {}

bodycad
Jerome Godbout
Software Developer
2035 rue du Haut-Bord, Québec, QC, Canada. G1N 4R7
T:  +1 418 527-1388
E: jer...@bodycad.com
www.bodycad.com

The contents of this email message and any attachments are intended solely for the addressee(s) and may contain confidential and/or privileged information and may be legally protected from disclosure. If you are not the intended recipient of this message or their agent, or if this message has been addressed to you in error, please immediately alert the sender by reply email and then delete this message and any attachments. If you are not the intended recipient, you are hereby notified that any use, dissemination, copying, or storage of this message or its attachments is strictly prohibited. 

Le contenu de ce message et les pièces jointes sont destinés uniquement pour le(s) destinataire(s) et peuvent contenir des informations confidentielles et / ou privilégiées qui peuvent être protégées légalement contre toute divulgation. Si vous n'êtes pas le destinataire de ce message ou son agent, ou si ce message vous a été adressé par erreur, s’il vous plaît avertir immédiatement l'expéditeur par courriel de réponse, puis supprimer ce message et les pièces jointes. Si vous n'êtes pas le destinataire prévu, vous êtes par la présente informé que toute utilisation, diffusion, copie, ou stockage de ce message ou de ses pièces jointes est strictement interdit.


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/Hbv3-F842pE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2422569c-e252-4553-bcb3-1f6c79aa5898%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Baswaraj Malage

unread,
Mar 13, 2017, 1:56:39 AM3/13/17
to Jenkins Users
Hey Jerome
I'm using latest stable version of Jenkins and my pipeline node script looks as below.


node {
stage('checkout') {
git '...........github link...........'
}
stage('build and test') {
bat 'npm install'
bat 'npm run test'            
}
stage('archive') {
bat 'zip zipFile: \'screen.zip\' archive: true dir: \'screenprint\' glob: \'**/*.png\''            
}      
}


Thanks
Baswaraj 

Jérôme Godbout

unread,
Mar 13, 2017, 8:58:17 AM3/13/17
to jenkins...@googlegroups.com
No need to use 'bat' command, there is a zip command directly. Change:

bat 'zip zipFile: \'screen.zip\' archive: true dir: \'screenprint\' glob: \'**/*.png\''

for this: 

zip zipFile: 'screen.zip' archive: true dir: 'screenprint' glob: '**/*.png'

it should work directly


bodycad
Jerome Godbout
Software Developer
2035 rue du Haut-Bord, Québec, QC, Canada. G1N 4R7
T:  +1 418 527-1388
E: jer...@bodycad.com
www.bodycad.com

The contents of this email message and any attachments are intended solely for the addressee(s) and may contain confidential and/or privileged information and may be legally protected from disclosure. If you are not the intended recipient of this message or their agent, or if this message has been addressed to you in error, please immediately alert the sender by reply email and then delete this message and any attachments. If you are not the intended recipient, you are hereby notified that any use, dissemination, copying, or storage of this message or its attachments is strictly prohibited. 

Le contenu de ce message et les pièces jointes sont destinés uniquement pour le(s) destinataire(s) et peuvent contenir des informations confidentielles et / ou privilégiées qui peuvent être protégées légalement contre toute divulgation. Si vous n'êtes pas le destinataire de ce message ou son agent, ou si ce message vous a été adressé par erreur, s’il vous plaît avertir immédiatement l'expéditeur par courriel de réponse, puis supprimer ce message et les pièces jointes. Si vous n'êtes pas le destinataire prévu, vous êtes par la présente informé que toute utilisation, diffusion, copie, ou stockage de ce message ou de ses pièces jointes est strictement interdit.


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/Hbv3-F842pE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

Baswaraj Malage

unread,
Mar 14, 2017, 2:36:20 AM3/14/17
to Jenkins Users
Thanks Jerome for all your suggestion. But, no luck to get files in zip. I did use zip directly (I had to separate commands with ,) but did not work for me. I might be missing something or jenkins yet to support this feature.

zip zipFile: 'screen.zip', archive: true, dir: 'screenprint', glob: '**/*.png'


-Baswaraj

jer...@bodycad.com

unread,
Mar 21, 2017, 12:03:50 PM3/21/17
to Jenkins Users
zip zipFile: "x64\\Release\\${APPLY_TAG}.zip", dir: "x64\\Release\\${APPLY_TAG}";
archiveArtifacts artifacts: "x64\\Release\\${APPLY_TAG}.zip", fingerprint: false, allowEmptyArchive: false, onlyIfSuccessful: true;

This work for me, make sure your path are adapted to the platform (Unix vs Windows). Not sure about the wildcard, may want to try without and a simple file to see which part is messing around. I have tryt the archiving of zip command yet. I do the archiving manually after.

Ashwath Mendan

unread,
Jun 10, 2022, 8:12:02 AM6/10/22
to Jenkins Users
Hi , 

I'm looking for exclude option, looks like exclude is not working, can anyone share the working syntax for exclude with zip step?

Reply all
Reply to author
Forward
0 new messages