Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to zip a dir in pipeline step

Deleted user November 18, 2017

I have a number of files being generated from my build which I want to publish together in a single zip file. I tried scripting this making use of the 'zip' command, however I get the following error. Is this possible?

bash: zip: command not found

 

2 answers

7 votes
Stephan Hradek January 16, 2018

I'm using this workaraound now:

Instead of

- zipfile="filename"
- dir="directory"
- zip -r $zipfile.zip $dir

I'm using pythons like so:

- zipfile="filename"
- dir="directory"
- python -c "import shutil;shutil.make_archive('$zipfile','zip',root_dir='.', base_dir='$dir')"

This will create a zipfile without having to install zip

Vicente Amorós Aldea April 11, 2019

Thank you ! you saved my day =) 

Pedro Guerrato June 11, 2019

And mine!

0 votes
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 24, 2017

Hi Jon, can you show us your bitbucket-pipelines.yml file? Can you confirm you have 'zip' installed?

Regards!

Ana

Stephan Hradek January 16, 2018

Hi Ana,

I also want to zip in a pipeline and I also come across the error

 

    bash: zip: command not found

 

Could you please assist: How could I get zip installed (in a pipeline) so that I can use it?

Vimal krishnamoorthy October 16, 2018

I want to do the same thing . Want to zip the files in the repository using bitbucket pipeline yml file

 

Please anyone  , guide me ?

Asim AlTwaijri October 18, 2018

add this command to your scripts:

- apt-get install zip

Stephan Hradek October 18, 2018

Or - if you have python available - use my above-described workaround

Vimal krishnamoorthy October 18, 2018

I tried with python and this is what i am getting as error. I am very new to bitbucket pipeline , 

 

python -c "import shutil;shutil.make_archive('$zipfile','zip',root_dir='.', base_dir='$dir')"<1s+ python -c "import shutil;shutil.make_archive('$zipfile','zip',root_dir='.', base_dir='$dir')"Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/local/lib/python3.5/shutil.py", line 794, in make_archive filename = func(base_name, base_dir, **kwargs) File "/usr/local/lib/python3.5/shutil.py", line 683, in _make_zipfile zf.write(path, path) File "/usr/local/lib/python3.5/zipfile.py", line 1441, in write while arcname[0] in (os.sep, os.altsep):IndexError: string index out of range

Stephan Hradek October 18, 2018

You've set zipfile and dir?
What's the "<1s+"?

Vimal krishnamoorthy October 18, 2018

my yml file looks as follows. Just trying a simple example. 

Capture.PNG 

and this is my bitbucket repo: I need to have a web.zip in the repo after the pipeline execution. is it possible with this approach?

Capture.PNG

Stephan Hradek October 18, 2018

I'm not sure you can use ./ as a basedir. I#m also neither a pipeline nor a python expert.

Maybe take a look at the documentation for shutil.make_archive or check this https://stackoverflow.com/questions/32640053/compressing-directory-using-shutil-make-archive-while-preserving-directory-str

Like Vimal krishnamoorthy likes this
Vimal krishnamoorthy October 24, 2018

Thanks Stephan.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events