【问题标题】:How to get url when searching using the artifactory jfrog cli使用神器 jfrog cli 搜索时如何获取 url
【发布时间】:2023-03-03 22:23:01
【问题描述】:

Artifactory 的jfrog cli 可用于跨~/.jfrog/jfrog-cli.conf 中配置的多个服务器搜索工件:

jfrog rt s repo_name/path/to/artifact*

结果中的 URL 只是相对于服务器基本 URL 的部分,并且不包含对找到工件的服务器的任何引用:

[
    {
        "path": "repo_name/path/to/artifact.tar"
    }
]

我知道可以遍历配置文件中的服务器列表,或者使用 REST API,但我希望 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"
}

【问题讨论】:

    标签: artifactory jfrog-cli


    【解决方案1】:

    jfrog cli 不会搜索已配置服务器的列表。相反,应该使用jfrog rt s 的--server-id 选项,或者使用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-server-1

    这会将给定服务器的isDefault 设置更新为true,其余部分更新为false。 我不建议在脚本中使用这种方式,因为如果一次执行多个脚本会产生干扰。

    服务器应该一个接一个地循环,服务器 URL 从 jfrog-cli.conf JSON 中选择,或者使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多