2017-08-25 158 views
0

jfrog CLI为Artifactory的可用于搜索跨多个服务器文物在~/.jfrog/jfrog-cli.conf配置进行搜寻时,网址:如何使用artifactory的jfrog CLI

jfrog rt s repo_name/path/to/artifact* 

在结果中的URL只是相对部分服务器基本URL,并且不包含到服务器的任何引用,其神器发现:

​​

我知道可以遍历服务器列表中的配置文件,或者使用REST API,但我会prefe r如果cli能够返回它。我还没有找到任何可以告诉jfrog在结果中包含服务器URL的选项,所以看起来这是不可能的。希望我错了。

该URL将在下游事件中发送给其他不知道ARM是什么的组件。

样品jfrog-cli.conf

{ 
    "artifactory": [ 
    { 
     "url": "https://arm1.foo.bar/artifactory/", 
     "apiKey": "AKEY", 
     "serverId": "1", 
     "isDefault": true 
    }, 
    { 
     "url": "https://arm2.foo.bar/artifactory/", 
     "apiKey": "ANOTHERKEY", 
     "serverId": "2", 
     "isDefault": false 
    } 
    ], 
    "Version": "1" 
} 

回答

0

jfrog CLI不会跨越配置的服务器的列表中进行搜索。应该使用--server-id选项jfrog rt s或使用jfrog rt use <server id>来设置默认服务器,请参阅https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-UsingaPredefinedArtifactoryServer

您可以使用config命令配置多个Artifactory实例。 'use'命令用于指定哪些配置的Artifactory实例应该用于以下CLI命令。

$ jfrog RT使用artifactory的服务器-1

这将更新isDefault设置true对于给定的服务器,并为false休息。 我不会推荐在脚本中使用这种方式,因为如果一次执行多个执行,会有干扰。

服务器应该循环一个接一个,并从jfrog-cli.conf JSON中选取服务器URL,或使用jfrog rt c show <server id>命令。一些python代码:

import json 
import os 
from subprocess import check_output 

def find_one_artifact(pattern): 
    # Make jfrog less talkative so that JSON parsing works 
    os.environ['JFROG_CLI_LOG_LEVEL'] = 'ERROR' 
    with open(os.getenv('HOME') + '/.jfrog/jfrog-cli.conf') as fp: 
     conf = json.load(fp) 
     for server in conf['artifactory']: 
      output = check_output(['jfrog', 'rt', 's', '--server-id', 
            server['serverId'], pattern]) 
      hits = json.loads(output) 
      if hits and 'errors' not in hits: 
       for hit in hits: 
        return server['url'] + '/' + hit['path'] 
    return None 
相关问题