JFROG相关API

JFROG Artifactory相关API

一、通用命令

由于Artifactory是http类服务,所以可以直接用wget或curl等命令进行上传下载。

下载:

curl -u<USERNAME>:<PASSWORD> -O "http://jfrog.company.com:8081/artifactory/test-local/<TARGET_FILE_PATH>"

上传:

curl -u<USERNAME>:<PASSWORD> -T <PATH_TO_FILE> "http://jfrog.company.com:8081/artifactory/test-local/<TARGET_FILE_PATH>"

二、Jfrog Artifactory API

官方文档:https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli

2.1 下载安装jf cli

curl -fL https://install-cli.jfrog.io | sh

最后会提示:

The jf executable was installed in /usr/local/bin
可以到/usr/local/bin下面查看,有一个jf文件

2.2 配置jfrog 环境

jf config add current --url http://ip:8082/ --user username --password userpasswd

以上命令是创建一个叫current的jfrog环境,http://ip:8082/ 是当前jfrog aritfactory的url,–user,–password对应用户和密码,接下来的操作将是用该用户进行,该用户需要有相关的下载或上传权限。

2.3 jfrog相关操作

  • 下载artifacts到本地
jf config use current
jf rt download --threads 15 $dest_dir/*

d e s t d i r 为要下载的 a r t i f a c t s 路径。这条命令会将 dest_dir为要下载的artifacts路径。这条命令会将 destdir为要下载的artifacts路径。这条命令会将dest_dir下的所有文件递归下载到本地。

如$dest_dir设为test_repo,会将test_repo仓库下的所有文件下载到本地。

  • 上传artifacts到jfrog artifactory
ls | while read ITEM; do jf rt u --threads=10 --flat=false --recursive=true  $ITEM/  test_repo/; done

将当前路径下的所有文件递归上传到jfrog artifactory的test_repo仓库下。

  • 清除jfrog artifactory平台的artifacts(谨慎使用)
jf rt delete --threads 15 test_repo/*

清除test_repo仓库下的所有文件。

  • 查询当前artifacts信息

可以结合aql进行查询。

jf rt search --spec=./test.aql

cat test.aql
{
  "files":
    [
      {
        "aql":
          {
            "items.find" :
               {
                 "type":"file",
                 "repo":"reponame",
                 "path":{"$match":"release/tests/*"}
               }
          },
          "recursive": "true"
      }
    ]
}
# 结合该test.aql可以查询reponame仓库中release/tests/路径下所有artifacts的信息,信息的解析可以通过python完成。
def run_cmd(cmd):
    """ Execute shell command and return the results or exit with Error message."""
    print(f"Running Command: {cmd}")
    process = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
    (stdout, stderr) = process.communicate()
    process_rc = process.returncode

    if process_rc:
        print(stderr)
        print(f"ERROR: Command return code {process_rc}.")
        sys.exit(1)

    return stdout
    
if __name__ == "__main__":
    output = run_cmd(f"jf rt search --spec=./test.aql").decode('utf-8')
    print(output)
    for item in json.loads(output):
        file_key = item['path']
        file_md5 = item['md5']

三、jfrog artifactory API应用

https://jfrog.com/help/r/artifactory-how-to-manually-synchronize-a-single-repository/artifactory-how-to-manually-synchronize-a-single-repository

同步两个jfrog artifactory:

  1. Download and install the JFrog CLI on the New Artifactory - Configure it to recognize Old and New servers:
jfrog config add old #Fill out connection details for the Source Artifactory
jfrog config add new #Fill out connection details for the Target Artifactory
  1. Download the current contents of the Old Artifactory’s repository. “Migration-Repository” is used in this example.

    #Perform this on a mounted disk location with at least the repository’s size available on the disk

    mkdir -p /tmp/Migration-Repository
     
    cd /tmp/Migration-Repository
     
    jfrog config use old
     
    #Adjust "--threads" setting as necessary
    jfrog rt download --threads 15 Migration-Repository/*
    
  2. (Optional) If this is a replacement of data on the New Artifactory, you have to delete the contents there to replace it effectively. Only do this if this is a replacement and not an update.

jfrog config use new
 
#Will delete 15 things at a time
jfrog rt delete --threads 15 Migration-Repository 
  1. Get the data up into the New Artifactory, “Migration-Repository” is used here but the upload can be to a different repository:
jfrog config use new
 
ls | while read ITEM; do jfrog rt u --threads=10 --flat=false --recursive=true  $ITEM/ Migration-Repository/; done

The final upload sequence will push up all of the downloaded data to the New Artifactory.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值