Artifactory Rest API(快速搜索)-指定“回购”时通配符的正确用法是什么?

时间:2019-04-12 21:24:35

标签: artifactory

我正在尝试使用Artifactory快速搜索API(https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactSearch(QuickSearch))查找给定工件的URL,同时为其提供带通配符的repo参数。只有回购值完全匹配时,我才能得到结果。

工件具有以下通用属性: build.name(IE:Enterprise-Communications :: NativeVXML-CICD-TestDemo :: v1.2.7rc) build.number(IE:1) build.timestamp(unix时间戳) 标签(Git标签版本号) vcs.revision(认为它是git的commit_id)

我无法调出我检查过的所有站点和页面,但这是一个使用*和?显示UI的页面。作为通配符。 https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API

我们的Artifactory公司是地理冗余的,并且使用[部门]-[用途]-[环境]的根目录命名约定,因此诸如“ SysDev-general-dev”和“ SysDev-general-prod”之类的内容QA / UAT接受完成后,将文件从-dev复制到-prod的管道过程。

该工件已上传到“ SysDev-general-dev / clientName / program / artifact.tar”的存储库/文件夹,然后系统显然向该存储库添加了“-[Site]”引用(“ SysDev- general-dev-DEN01”),但只有登录到特定于站点的用户界面之一或使用搜索API时,该站点标识符才可见。


**注:使用带有'uri'的Chrome,FireFox和Ansible剧本进行的测试 模块。

使用工件名称执行快速搜索时,它将返回预期的URL列表。 “ artifactory / api / search / artifact?name = NativeVXML-CICD-TestDemo.v1.2.7”

{ "results" : [ { "uri" : "http://<DOMAIN>/artifactory/api/storage/Enterprise-Communications-generic-preprod-SWN01/nreddy/NativeVXML-CICD-TestDemo/NativeVXML-CICD-TestDemo.v1.2.7.tar" }, { "uri" : "http://<DOMAIN>/artifactory/api/storage/Enterprise-Communications-generic-prod-SWN01/nreddy/NativeVXML-CICD-TestDemo/NativeVXML-CICD-TestDemo.v1.2.7.tar" } ] }


使用完全匹配的仓库过滤器返回我想要的1个URI。 &repos = Enterprise-Communications-Generic-preprod-SWN01 { "results" : [ { "uri" : "http://<DOMAIN>/artifactory/api/storage/Enterprise-Communications-generic-preprod-SWN01/nreddy/NativeVXML-CICD-TestDemo/NativeVXML-CICD-TestDemo.v1.2.7.tar" } ] }


在根目录的第一部分添加“&repos =“以过滤返回值时,将返回空结果集。 “ artifactory / api / search / artifact?name = NativeVXML-CICD-TestDemo.v1.2.7.ta​​r&repos = Enterprise-Communications-generic-preprod”

{ "results" : [ ] }


在通配回购名称中添加*: “ artifactory / api / search / artifact?name = NativeVXML-CICD-TestDemo.v1.2.7.ta​​r&repos = Enterprise-Communications-generic-preprod” { "results" : [ ] }


将回购名称(用)括在引号中 artifactory / api / search / artifact?name = NativeVXML-CICD-TestDemo.v1.2.7.ta​​r&repos =“ Enterprise-Communications-generic-preprod { "results" : [ ] }


将回购名称(带*)括在引号和URL编码中: artifactory / api / search / artifact?name = NativeVXML-CICD-TestDemo.v1.2.7.ta​​r&repos =%22Enterprise-Communications-generic-preprod%A2%22 { "results" : [ ] }


将回购名称(用?)引起来 artifactory / api / search / artifact?name = NativeVXML-CICD-TestDemo.v1.2.7.ta​​r&repos =“ Enterprise-Communications-generic-preprod?” { "results" : [ ] }

剧本:

- name: "Search URL: {{find_uri}} " uri: url: '{{ find_uri }}' method: GET # Default is GET force_basic_auth: yes validate_certs: no return_content: yes timeout: 15 #Default is 30 register: artifact_list

我真正想做的是使用通配符传递回购引用,并仅获取包含该值的URI值。

IE:&repos =“ Enterprise-Communications-generic-preprod *”

{ "results" : [ { "uri" : "http://<DOMAIN>/artifactory/api/storage/Enterprise-Communications-generic-preprod-SWN01/nreddy/NativeVXML-CICD-TestDemo/NativeVXML-CICD-TestDemo.v1.2.7.tar" } ] }

1 个答案:

答案 0 :(得分:0)

嗯,这不是我想要的方式,但是我确实得到了一些简单的Jinja语句来帮助我过滤返回的URL映射。

- set_fact:
    artifact_url: "{{ (artifact_list.content | from_json ).results | map(attribute='uri') | select('match', artifact_root_dir) | list  }}" # will return a list or empty
    failed_when:  not artifact_url or artifact_url | length != 1    #fail when not set/empty or list contains more than 1