Reputation: 23
I'm trying to use the Artifactory Quick Search API (https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ArtifactSearch(QuickSearch)) to find the URL to a given artifact while giving it the repo parameter with a wildcard in it. I can only get a result when the repo value is an exact match.
Artifacts are being loaded with these generic properties: build.name (IE:Enterprise-Communications :: NativeVXML-CICD-TestDemo :: v1.2.7rc) build.number (IE: 1) build.timestamp (unix time stamp) tag (Git tag version number) vcs.revision (think it's git's commit_id)
I can't recall all of the sites and pages I've checked but here is one that shows the UI using * and ? as wildcards. https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API
Our company Artifactory is geo-redundant and using a root directory naming convention of [Department]-[purpose]-[environment], so something like "SysDev-general-dev" and "SysDev-general-prod" with a pipeline process of copying the file from -dev into -prod once QA/UAT acceptance is complete.
The artifact is uploaded to a repo/folder of "SysDev-general-dev/clientName/program/artifact.tar" and apparently the system is then adding a "-[Site]" reference to the repo ("SysDev-general-dev-DEN01"), but that site identifier is only visible when logged into one of the site specific UIs or using the search APIs.
** Note: tests done with Chrome, FireFox, and Ansible playbook w/ 'uri' module.
When performing a Quick Search with the artifact name, it returns a list of URLs as expected. "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"
} ]
}
Using repo filter with exact match returns the 1 URI that I want.
&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"
} ]
}
When adding "&repos=" with the first piece of the root dir to filter the return, an empty result set is returned. "artifactory/api/search/artifact?name=NativeVXML-CICD-TestDemo.v1.2.7.tar&repos=Enterprise-Communications-generic-preprod"
{
"results" : [ ]
}
Add * to wildcard repo name:
"artifactory/api/search/artifact?name=NativeVXML-CICD-TestDemo.v1.2.7.tar&repos=Enterprise-Communications-generic-preprod"
{
"results" : [ ]
}
Wrap repo name (with ) in quotes
artifactory/api/search/artifact?name=NativeVXML-CICD-TestDemo.v1.2.7.tar&repos="Enterprise-Communications-generic-preprod"
{
"results" : [ ]
}
Wrap repo name (with *) in quotes and URL encode:
artifactory/api/search/artifact?name=NativeVXML-CICD-TestDemo.v1.2.7.tar&repos=%22Enterprise-Communications-generic-preprod%A2%22
{
"results" : [ ]
}
Wrap repo name (with ?) in quotes
artifactory/api/search/artifact?name=NativeVXML-CICD-TestDemo.v1.2.7.tar&repos="Enterprise-Communications-generic-preprod?"
{
"results" : [ ]
}
Playbook:
- 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
What I really want to do is pass in a repo reference with a wild card and get only URI values back that contain that value.
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"
} ]
}
Upvotes: 1
Views: 1205
Reputation: 1
Well, it isn't the way I'd prefer to do it but I did get a couple of simple Jinja statements to help me filter down the returned map of URLs.
- 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
Upvotes: 0