![](/img/trans.png)
[英]Artifactory CLI - Jfrog - How to get binary Hash code (SHA1, SHA256) through jfrog CLI
[英]How to get url when searching using the artifactory jfrog cli
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"
}
jfrog
cli不会在已配置服务器的列表中搜索。 而是应使用jfrog rt s
--server-id
选项,或jfrog rt use <server id>
来设置默认服务器,请参见https://www.jfrog.com/confluence/display/CLI/CLI+ for + JFrog + Artifactory#CLIforJFrogArtifactory-Usinga预定义的ArtifactoryServer 。
您可以使用config命令配置多个Artifactory实例。 “ use”命令用于指定以下CLI命令应使用哪个已配置的Artifactory实例。
$ jfrog rt使用artistory-server-1
对于给定的服务器,这isDefault
设置更新为true
,对于其余服务器,将其更新为false
。 我不建议在脚本中使用这种方式,因为如果一次执行多个指令,将会产生干扰。
服务器应一一循环,并从jfrog-cli.conf JSON或使用jfrog rt c show <server id>
命令中选择服务器URL。 一些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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.