0
votes

I'm having an issue with using the Artifactory REST API to create virtual repositories that I've struggled with the last couple days. No issues with local or remote repositories. I am able to get the Virtual repository created using only the required JSON entries, but I would like to add more to that. I want to store the JSON for future reference so we can refer back to it if we ever wish to create other virtual repositories (as a template of sorts).

I'm doing this with PowerShell. I'm passing a list of repository names. The Script parses the repository name and collects an appropriate config file containing the JSON values.

Create repository API info: https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-CreateRepository

Accepted values: https://www.jfrog.com/confluence/display/RTF/Repository+Configuration+JSON#RepositoryConfigurationJSON-application/vnd.org.jfrog.artifactory.repositories.VirtualRepositoryConfiguration+json

Here is the JSON that works successfully: (only passing required fields)

{
"rclass" : "virtual",
"packageType": "nuget"
}

However, it appears that when I try to add any other properties to it I get failures. Here is everything I would like to pass followed by the error I get when I do. (Sanitized values for public posting.)

{
"rclass" : "virtual",
"packageType": "nuget",
"repositories": ["nuget-local,nuget-remote"], 
"description": "Nuget virtual repository.",
"notes": "Created by PowerShell script.",
"includesPattern": "*.nupkg",
"excludesPattern": "*mvn,*npm",
"defaultDeploymentRepo": "nuget-local"
}

Invoke-WebRequest : The remote server returned an error: (400) Bad Request. At [path to ps1 file.]:226 char:5 + Invoke-WebRequest -Method Put -Uri $resource -Body $RepoConfig -H ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Thank you for your time.

1
Not sure if this is the issue, but your "repositories": ["nuget-local,nuget-remote"], line should be "repositories": ["nuget-local","nuget-remote"],. It should be a list of two strings, rather than a list of one string with a comma in it.DarthFennec
Wow, I swear I tried that and it failed, but I just tried it again and it worked... so I'll mark that as an issue resolved. Thanks!jdtech82

1 Answers

1
votes

Per DarthFennec's comment on my question it turns out I had the formatting wrong:

Not sure if this is the issue, but your "repositories": ["nuget-local,nuget-remote"], line should be "repositories": ["nuget-local","nuget-remote"],. It should be a list of two strings, rather than a list of one string with a comma in it. – DarthFennec 16 hours ago