JFrog CLI无法在JFrog Artifactory中的工件上设置属性以获取第一个属性名称,并且无法使用SSH密钥示例进行多属性搜索 [英] JFrog CLI can't set properties on an artifact in JFrog Artifactory for the first property name and using SSH key examples for multi property search
问题描述
JFrog Artifactory: 5.8.4专业版.
JFrog Artifactory: 5.8.4 Professional.
JFrog CLI: 1.12.1
我正在使用 JFrog CLI的官方文档为Artifactory回购中可用的工件设置一些属性.
I'm using the official documentation of JFrog CLI to set few properties on an artifact that's available in Artifactory repo.
- 注意:我现在不想使用
Artifactory AQL
并尝试使用jfrog
cli使其正常工作.
- NOTE: I don't want to use
Artifactory AQL
for now and trying to get this working usingjfrog
cli.
我成功配置了CLI客户端(文件~/.jfrog/jfrog-cli.conf
已成功创建,其中包含使用用户名/密码和API密钥进行身份验证的条目).
I successfully configured the CLI client (the file ~/.jfrog/jfrog-cli.conf
with entries for authentication using either username/password and with an API Key was created successfully).
要在工件上设置属性,请参考以下示例:
For setting properties on an artifact, I referred the following example:
jfrog rt sp "generic-local/*.zip" "a=1;b=2,3"
并运行以下命令(在自由样式的Jenkins作业中):
and ran the following command (in a free-style Jenkins job):
$ jfrog rt sp --server-id="artifactory-dev-instance" --url=${ARTIFACTORY_URL} ${REPO}/${FILE_PATH}/${FILE_NAME} -- props="release=${RELEASE};VERSION=${VERSION};PIPELINE_VERSION=${RELEASE}_${VERSION}_${BUILD_NUMBER};fileType=automated-file;PROJECT=${PROJECT}"
此命令成功退出,没有给出错误,并且将除第一个属性release=${RELEASE}
之外的所有属性都应用了期望值.
This command exited successfully without giving an error and applied all the properties with expected values except the first property release=${RELEASE}
.
问题:为什么jfrog rt sp
没有在工件上应用release
属性,而所有其他属性都已成功应用正确的值.
Question: Why jfrog rt sp
is not applying the release
property on the artifact while all others properties got successfully applied with correct values.
实际变量值无关紧要,因为我可以看到其他属性已成功应用于给定的Artifactory实例(ARTIFACTORY_URL),目标文件(位于repo/path/file中)以及具有其值的各个属性.
Actual variables values don't matter as I can see other properties getting applied successfully in the given Artifactory instance (ARTIFACTORY_URL), on the target file (sitting in a repo/path/file) and respective properties with their values.
推荐答案
因此,这实际上证明了这一点(jfrog
cli中的 bug 部分).重新添加该第一个属性,即,将缺少的第一个属性添加两次,它适用于所有属性(包括第一个属性),同时提供要添加的属性.
So, this proves it actually (bug part in jfrog
cli). re-add that first property i.e. add the missing first property twice and it works for all properties (including the first one) while giving properties to be added.
现在release
属性也正在应用.
$ jfrog rt sp --server-id="artifactory-dev-instance" --url=${ARTIFACTORY_URL} ${REPO}/${FILE_PATH}/${FILE_NAME} -- props="release=${RELEASE};release=${RELEASE};VERSION=${VERSION};PIPELINE_VERSION=${RELEASE}_${VERSION}_${BUILD_NUMBER};fileType=automated-file;PROJECT=${PROJECT}"
或
$ jfrog rt sp --server-id="artifactory-dev-instance" --url=${ARTIFACTORY_URL} ${REPO}/${FILE_PATH}/${FILE_NAME} -- props="release=${RELEASE};VERSION=${VERSION};PIPELINE_VERSION=${RELEASE}_${VERSION}_${BUILD_NUMBER};fileType=automated-file;PROJECT=${PROJECT};release=${RELEASE}"
注意:设置属性jfrog rt sp
时,可以使用,
即--props="prop1=value1;prop2=value22,prop2=value23;prop3=value3"
为同一属性名称指定多个值,但是在jfrog rt s
(搜索)期间,不能使用,
(如果完全使用,
或;
来匹配一个以上可能的值的属性,jfrog rt s --prop="..."
不会为您提供所有结果,因为它将仅选择最后一个值并覆盖该值的所有其他先前值给定的属性).
NOTE: While setting properties jfrog rt sp
, you can specify multiple values for the same property name using ,
i.e. --props="prop1=value1;prop2=value22,prop2=value23;prop3=value3"
but during jfrog rt s
(search), you can't use ,
(if you use ,
or ;
at all for matching a property for more than 1 possible values, jfrog rt s --prop="..."
is not going to give you all the results as it'll pick only the last value and override all other previous values for that given property).
使用jfrog
cli --server-id ="..."和--url ="Artifactory URL"(如上所述)的ALSO,可以以更安全的方式使用如果您使用SSH密钥.
ALSO, using jfrog
cli --server-id="..." and --url="Artifactory URL" (as listed above) can be used in a more secure way if you use SSH key.
将JFROG与SSH密钥配合使用(用于更好的身份验证)的示例在命令行中不需要用户名/密码或服务器ID(这需要〜/.jfrog/jfrog.conf文件):
Example of using JFROG with SSH key (for better authentication) doesn't require username/password or server-id at command line (which requires ~/.jfrog/jfrog.conf file):
只需创建您的SSH发布/私钥.为用户添加发布密钥(在Artifactory范围/仓库范围设置中运行命令),然后将JFROG_URL变量设置为:
Just create your SSH pub/private key. Add pub key for the user (running the command in Artifactory wide/repo wide settings), then set JFROG_URL variable as:
JFROG_URL="ssh://artifactory-develop:1339"
然后简单地运行:
要在工件上设置属性:
jfrog rt sp --ssh-key-path=/home/${USER}/.ssh/id_rsa --url=${JFROG_URL} ...same command as above for sp command
For setting properties on an artifact:
jfrog rt sp --ssh-key-path=/home/${USER}/.ssh/id_rsa --url=${JFROG_URL} ...same command as above for sp command
或用于搜索
jfrog rt s --ssh-key-path=/home/${USER}/.ssh/id_rsa --url=${JFROG_URL} ...same command as above for s searching artifacts
(请参阅其文档站点上的JFROG cli帮助).
jfrog rt s --ssh-key-path=/home/${USER}/.ssh/id_rsa --url=${JFROG_URL} ...same command as above for s searching artifacts
(see JFROG cli help on their documentation site).
JFROG cli在给定属性的--props="...."
部分中不支持'AND'和'OR',即,如果您要搜索属性prop1
包含多个值的工件,则jfrog
cli如上所示,使用--props="....."
无效.
JFROG cli does NOT support 'AND' and 'OR' within --props="...."
section for a given property i.e. if you want to search for an artifact where a property prop1
contains more than one value, then jfrog
cli as shown above which uses --props="....."
won't work.
为此,您可以使用JFrog文件搜索架构,并在-T file.json
中使用--spec ~/somefile.json
选项或curl命令.
For that, you have the use JFrog file search schema and use --spec ~/somefile.json
option or curl command with -T file.json
.
注意:打开{
和}
的json文件(语法)在您使用jfrog
(与--spec file.json一起使用)和使用-T file.json
NOTE: The json file (syntax) for opening {
and }
is different when you use jfrog
(with --spec file.json) and when you use curl
with -T file.json
让我们首先了解如何与curl
命令一起使用.
Let's see how to use with curl
command first.
创建一个包含以下内容的curl-aql.json
文件(例如):
Create a curl-aql.json
file which contains the following (as an example):
items.find(
{ "repo": { "$eq" : "libs-snapshot-local" }},
{ "@yourCustomProperty1": { "$match" : "someValue1" }},
{ "@yourCustomProp2": { "$match" : "anotherValue2" }},
{ "@moreCustomProps3": { "$match" : "string_or_number_or_alnum" }},
{ "$or":[ { "@customPropertyWhichHasMultipleValues" : "PASS", "@customPropertyWhichHasMultipleValues" : "UNSTABLE" } ]}
).include("*", "@customProperty5iWantAQLToReturnToMeBack", "@yourCustomProperty1","@yourCustomXProp","@yourCustomYProp")
注意::您创建的所有属性(即Artifactory不会免费提供给您的属性,例如"name","repo")必须以 @ 为前缀AQL中的字符,因为您会发现奇怪的错误消息,提示字符#74或75格式有问题.
NOTE: All properties which you create (i.e. which Artifactory doesn't give you for free like 'name', 'repo') MUST be prefixed with an @ character in AQL for you'll find a weird error mesg about something wrong with format at character # 74 or 75.
然后运行以下curl
命令(用户ID为: 123456 ,密码包含在$p
中):
Then run this curl
command (user id is: 123456 and password is contained in $p
):
curl -u123456:$p -H 'content-type: text/plain' -X POST http://artifactory-develop:8081/artifactory/api/search/aql -T ~/curl-aql.json
这不太安全,但是效果很好(如果您在Jenkins中定义并屏蔽密码变量并调用脚本).尽管如此,我还是更愿意使用jfrog
--props="..."
进行简单搜索,或者使用--spec jsonfile
(对于更复杂的搜索或jfrog
CLI支持的其他操作),并使用--url=$JFROG_URL
(SSH url)的更多安全--ssh-key-path=/your/home/.ssh/your_private_key_id_rsa
方式.
This is less secure but works well (if you define and MASK the password variables in Jenkins and call your script). Still, I'd rather use jfrog
--props="..."
for simple searches or --spec jsonfile
(for more complex searches or other operations what jfrog
CLI supports) using MORE secure --ssh-key-path=/your/home/.ssh/your_private_key_id_rsa
way using --url=$JFROG_URL
(SSH url).
在jfrog
中,如果您想使用Artifactory的 AQL 功能,请尝试以下操作:
In jfrog
if you want to use Artifactory's AQL capabilities, then try this:
创建一个文件jfrog-aql.json
,其中包含:
Create a file jfrog-aql.json
containing:
{
"files": [
{
"aql":
{
"items.find":
{
"repo": "libs-snapshot-local" ,
"@yourCustomProperty1": { "$match" : "ABC1.22.33" },
"@yourCustomProperty2": { "$match" : "Project1" },
"name": { "$match" : "ArtifactX-*.json" },
"@yourCustomProperty3": { "$match" : "2.*" },
"@yourCustomProperty4": { "$match" : "some-manifest-file" }
}
},
"sortBy" : ["created"],
"sortOrder" : "desc",
"limit" : 1
}
]
}
注意::此json文件具有jfrog
cli的--spec jsonfile
要求,并且语法与我们在json文件中使用的语法略有不同(在curl
运行期间).
NOTE: this json file has jfrog
cli's --spec jsonfile
requirements and have a little different syntax than what we used in the json file (during curl
run).
现在您可以使用jfrog
通过以下方式运行它:
Now you can run it using jfrog
via:
jfrog rt s --ssh-key-path=/home/${USER}/.ssh/id_rsa --url=${JFROG_URL} --spec ~/jfrog-aql.json
最后找到了更好的AQL,您可以在其中使用$and
或$or
来对单个属性的值进行多次搜索(可以通过对其进行调整来添加更多内容).在此处查看AQL文件:
Finally found a better AQL where you can use $and
or $or
for multi-search on values of a single property (you can add more by tweaking it). See AQL file here:
(注意:当值已知(即硬编码)时,使用$qa
比使用$match
更好,而使用simple form
更好(请参阅如何使用repo
当您的值中包含*
时,use或$match
才有意义,请参阅下面的name
属性用法):
(NOTE: It's better to use $qa
than using $match
when the value is known i.e. hard-coded and it's better to use simple form
(see how repo
is used below. Use or $match
makes sense when your value has *
in it, see how name
property is used below):
{
"files": [
{
"aql":
{
"items.find":
{
"repo": "libs-snapshot-local" ,
"@yourCustomProperty1": "ABC1.22.33",
"@yourCustomProperty2": "Artifact1",
"name": { "$match" : "ArtifactX-*.json" },
"@yourCustomProperty3": { "$match" : "2.*" },
"@yourCustomProperty4": "some-manifest-file",
"$or": [
{
"@customProperty5": "Hard-Coded-Known-Value1",
"@customProperty5": "Hard-Coded-Known-Value2"
}
]
}
},
"sortBy" : ["created"],
"sortOrder" : "desc",
"limit" : 1
}
]
}
注意:请参阅相关文章 Chef Berks如果您使用Chef
和berks install
(用于为稳定的重复部署查找和锁定食谱版本,并使用berks apply
(锁定版本),请安装(Berkshelf)超时联系Artifactory存储库(法拉第超时/Actor崩溃)食谱),并使用knife create <Chef-Env> -c ...
创建厨师环境/文件).
NOTE: See related post Chef Berks Install (Berkshelf) Timesout contacting Artifactory repository (Faraday Timeout / Actor Crashed) if you use Chef
and berks install
(for finding and locking cookbooks versions for stable repetitive deployments, using berks apply
(lock-in versions of cookbooks) and using knife create <Chef-Env> -c ...
for creating Chef Environments / Files).
这篇关于JFrog CLI无法在JFrog Artifactory中的工件上设置属性以获取第一个属性名称,并且无法使用SSH密钥示例进行多属性搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!