How to zip a dir in pipeline step

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

I'm using this workaraound now:

Instead of

- zipfile="filename"
- dir="directory"
- zip -r $ $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

0 votes

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



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?

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


Please anyone  , guide me ?

add this command to your scripts:

- apt-get install zip

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

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/", line 794, in make_archive filename = func(base_name, base_dir, **kwargs) File "/usr/local/lib/python3.5/", line 683, in _make_zipfile zf.write(path, path) File "/usr/local/lib/python3.5/", line 1441, in write while arcname[0] in (os.sep, os.altsep):IndexError: string index out of range

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

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


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


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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 06, 2018 in Bitbucket

Upgrade Best Practices

Hello! My name is Mark Askew and I am a Premier Support Engineer for products Bitbucket Server/Data Center, Fisheye & Crucible. Today, I want to bring the discussion that Jennifer, Matt, and ...

678 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you