You're checking to see if $artifact
ends in .zip
, but you don't actually set it when calling the script.
./script.pl --package_id=4370177 --artifact=test-1.0.zip
I would suggest cleaning up the parsing of your options, so that you actually do some error checking.
#!/usr/local/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
use Getopt::Long;
##input parameters
GetOptions(
"artifact=s" => \my $artifact,
"package_id=i" => \my $package_id,
) or usage();
usage("Unknown arguments: @ARGV\n") if @ARGV;
usage("--artifact is required\n") if ! $artifact;
usage("--package_id is required\n") if ! $package_id;
if ($artifact =~ /\.zip$/i) {
chdir("/apps/checkout/artifactory/xxkintana/$package_id");
unzip $artifact;
}
sub usage {
my $message = shift;
die "${message}Usage: ./$0 --artifact=<artifact> --package_id=<id>\n";
}
Finally, I would probably make additional error checking to ensure that the directory you're trying to chdir
exists, that $artifact
exists, and throw appropriate error messages for those and any more cases that you can think of.