0
votes

Artifact management system is JFrog Artifactory Pro X.

According to REST API of JFrog in my Jenkins job with REST API I try to get latest artifact version of a specific package, in this case the id is "MyLib".

My NuGet package is stored here: https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg?properties=nuget.version, which results in following JSON response:

{
  "properties" : {
    "nuget.version" : [ "1.0.0" ]
  },
  "uri" : "https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg"
}

Also with following URL: https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg?properties=nuget.id I get valid JSON response:

{
  "properties" : {
    "nuget.id" : [ "MyLib" ]
  },
  "uri" : "https://artifactory.myserver.net/artifactory/api/storage/projectx-nuget/MyLib/MyLib.1.0.0.nupkg"
}

I tried with following URL https://artifactory.myserver.net/artifactory/api/versions/_any/_any?nuget.id=MyLib, but got

{
  "errors" : [ {
    "status" : 404,
    "message" : "Not Found"
  } ]
}

What is the correct URL to get the latest version, based on the property "nuget.id"?

1
why there are two _any ? typo ?error404
@error404 According to jfrog.com/confluence/display/RTF3X/… the usage is GET /api/versions/{repo}/{path}?[listFiles=0/1]&[<property key>=<property value>]&[<property key>=<property value>], where ´{repo}: Specify a repository to search through or replace with "_any" to search through all repositories´ and ´{path}: Specify a path to search through or replace with "_any" to search through all paths´. So I replaced both variables with ´_any´.Chris

1 Answers

1
votes

According to the doc artifactory/api/versions : Search for artifacts with the latest value in the "version" property. Only artifacts with a "version" property expressly defined will be returned.

In your case you do not have the "version" property set (I guess) but only "nuget.version" which is extracted metadata from the nuget packages during indexation.

Just set a "version" property on the package and the REST call will work.

You can automate this by using a user plugin in artifactory that will set the "version" property after the package has been written.

Another solution without the need of a user plugin would be to use the native nuget api for example with nuget v3 api :

https://artifactory.myserver.net/artifactory/api/nuget/v3/projectx-nuget/query?q= MyLib&prerelease=false

Will give you a json response with latest version (and also a list of other versions as mentionned in doc https://docs.microsoft.com/fr-fr/nuget/api/search-query-service-resource : "The metadata contained in the search result object is taken from the latest package version. Each item in the versions array is a JSON object " )