Search code examples
artifactoryjfrog-cli

How to know programmatically when jfrog-cli is skipping an already existing file or artifact while downloading?


I'm using jfrog-cli in an automation which updates a database on every successful artifact download. The automation is written in Perl and it is simply using the system exit code jfrog process. Problem is, that jfrog-cli exits with exit code 0 each time it skips or successfully downloads any artifact.

Here is a pseudo code for what I'm doing-

system("jfrog rt dl --url https://$artifactory_server/artifactory --user $artifactory_username --password $artifactory_password $source $destination");
    if ($? == -1) {
            print "failed to execute: $!\n";
            # notify the failure
        }
    elsif ($? & 127) {
            printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
            # notify the failure
        }
    else {
            printf "child exited with value %d\n", $? >> 8;
            # update the database
        }

Solution

  • Before downloading a file, JFrog CLI compares the SHA1 of the local and remote files. If a file exists locally, JFrog CLI doesn't download it. In that case, you'll get a zero exit code because it represents success.

    Since the checksum download is good behavior that everyone can enjoy, it is preferred to be transient to the user.

    However, JFrog CLI can log when it skips downloading a file. One solution is to increase the log verbosity and parse the logs. You can do it by setting an environment variable JFROG_CLI_LOG_LEVEL=DEBUG and grep for these messages:

    [Debug] [Thread X]  File already exists locally.
    

    Another idea is to check if the file's timestamp had changed.

    You can read more about JFrog CLI checksum optimizations here.