Score:2

What is incorrect in ZIP command line?

hr flag

I am developing AWS Lambda (NET6). During the Github action execution (build, zip, upload) in a CloudFormation yml file, I have received the error:

Run zip -jr customerlambda-356e9e4b8869b2cf7f483d739aa5a8aa34e0fc13.zip -i ./bin/Release/net6.0/publish/*

zip error: Invalid command arguments (nothing to select from)
Error: Process completed with exit code 16.

It is in Ubuntu-latest environment.

What is incorrect here?

ar flag
Which distro and version of Linux are you using?
Score:6
jp flag

You seem to want:

zip -jr customerlambda-356e9e4b8869b2cf7f483d739aa5a8aa34e0fc13.zip \
./bin/Release/net6.0/publish/

i.e. without -i ... With the -i(include) option, you still haven't specified the path to the source file(s)/directory(ies) and hence the error:

zip error: Invalid command arguments (nothing to select from)

Notice one:

./bin/Release/net6.0/publish/ seems to be the relative path to where your source files/directories are, but adding -i before it will turn it into an argument to the -i option instead of an argument to the zip command itself ... Therefore as far as the zip command is concerned, there is no source file/directory argument ... and, you don't need to include that directory's contents with -i as the -r option will recurse through the contents of that directory so you dont need to use *(which you better escape with a backslash \* when used) either ... So simply remove -i and *.

Notice two:

The -j option will result in zip storing just the name(s) of a saved file(s) and not storing directory names(i.e. paths relative to the current directory) ... That might cause a problem when used with the -r option as duplicate identical filenames might exist in sub-directories that will be recursed by the option -r set which will result in zip receiving repeated filenames to store in the archive which it cannot do and will result in an error like:

zip error: Invalid command arguments (cannot repeat names in zip file)

So, you might not want to use -j in that case.

Notice three:

While relative paths in the form of ./subdir/subdir2/ and archive.zip will work and be parsed relative to the current working directory, it might be a good idea in scriptfiles to use the full real path for both the output archive and the source directory(ies)/file(s) like for example if your source directory is:

/home/runner/work/PM2AWSCustomers/PM2AWSCustomers/bin/Release/net6.0/publish/

and you want the resulting archive file named to be customerlambda.zip and saved in:

/home/runner/work/PM2AWSCustomers/

then use the zip command like so:

zip -r /home/runner/work/PM2AWSCustomers/customerlambda.zip \
/home/runner/work/PM2AWSCustomers/PM2AWSCustomers/bin/Release/net6.0/publish/

the backslash \ is used to escape the newline used for redability purposes in this post and will make the shell read the command as one liner ignoring the escaped newline.

ZedZip avatar
hr flag
These are source files ./bin/Release/net6.0/publish/
Raffa avatar
jp flag
@ZedZip That is clear to me, but adding `-i` before it will turn it into an argument to the `-i` option instead of an argument to the `zip` command itself ... Therefore as far as the `zip` command is concerned, there is no source file/directory argument ... and, you don't need to include that directory's contents with `-i` as the `-r` option will recurse through the contents of that directory so you dont need to use `*`(*which you better escape with a backslash when used*) either ... So simply remove `-i` and `*`.
ZedZip avatar
hr flag
I have added pwd and ls command to understand what is the current directory for zip
ZedZip avatar
hr flag
It is /home/runner/work/PM2AWSCustomers/PM2AWSCustomers PM2AWSCustomers <----folder PM2AWSCustomers.sln README.md aws I.e. I need to zip files in the folder PM2AWSCustomers/bin/Release/net6.0/publish what zip command should be in this case?
Raffa avatar
jp flag
@ZedZip I updated the answer for that ... I hope it's clear now.
ZedZip avatar
hr flag
Thank you @Raffa, so finally (without -j, -i and * at the end) : zip -r /home/runner/work/PM2AWSCustomers/customerlambda.zip \ /home/runner/work/PM2AWSCustomers/PM2AWSCustomers/bin/Release/net6.0/publish/
ZedZip avatar
hr flag
Thank you @Raffa, now it works!!! :-)
Raffa avatar
jp flag
@ZedZip You're welcome ... I'm glad I could help :-)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.