如何以编程方式知道 jfrog-cli 在下载时何​​时跳过已经存在的文件或工件?

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

我在自动化中使用 jfrog-cli,它会在每次成功下载工件时更新数据库。自动化是用 Perl 编写的,它只是使用系统退出代码 jfrog 进程。 问题是,每次跳过或成功下载任何工件时,jfrog-cli 都会以退出代码 0 退出。

这是我正在做的伪代码-

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
        }

在下载文件之前,JFrog CLI 会比较本地和远程文件的 SHA1。 如果文件存在于本地,JFrog CLI 不会下载它。在这种情况下,您将获得零退出代码,因为它代表成功。

由于校验和下载是每个人都可以享受的良好行为,因此最好对用户是短暂的。

但是,JFrog CLI 可以在跳过下载文件时进行记录。一种解决方案是增加日志的详细程度并解析日志。您可以通过为这些消息设置环境变量 JFROG_CLI_LOG_LEVEL=DEBUG 和 grep 来实现:

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

另一个想法是检查文件的时间戳是否已更改。

您可以阅读有关 JFrog CLI 校验和优化的更多信息here