Search code examples
linuxzipshbitbucket-pipelines

Error while using zip with -R@ options and file-list; "Invalid command arguments (nothing to select from)"


I am trying to deploy different groups of files (of many different types) to different environments using Bitbucket Pipelines and AWS CodeDeploy. In Pipelines, I use the zip command (from apt-get) to package up all the files for the specific environment and upload them to CodeDeploy (using the CodeDeploy pipe, which seems to expect a zip file).

A recent change has made it unwieldy to use a single line command to feed the all the necessary files to zip, so I instead would like to use a file list. The problem is that I have several sub-folders where I need to recursively grab all files, while in others I need to grab specific files. I also need to preserve the folder structure.

I also don't want to have to add every single path by hand if possible, as there are a lot of files in these sub-directories, and I also want to reduce the amount of cases where we forget to add new files to these lists. I also don't want to require the developer running a script locally, but I am okay with creating a script for use in Pipelines.

I tried to use the -R@ option with zip, but it gives the error zip error: Invalid command arguments (nothing to select from).

Example folder structure:

file1.txt
ziplist.txt
folder1/file2.js
folder1/file3.txt
folder1/folder2/file4.png
folder1/folder2/file5.jpg
folder1/folder3/file6.tsx
folder1/folder3/file7.mp3

The contents of ziplist.txt:

file1.txt
folder1/file2.js
folder1/folder2/file5.jpg
folder1/folder3/*

Using the command cat ziplist.txt | zip -R@ application.zip, I'd expect to have a zip with the following files inside:

file1.txt
folder1/file2.js
folder1/folder2/file5.jpg
folder1/folder3/file6.tsx
folder1/folder3/file7.mp3

Appreciate any help.


Solution

  • I was able to make it work by removing the /* for the folder path in the zip list, and then use xargs to convert the list to command line parameters, like so:

    cat ziplist.txt | xargs zip -r application.zip