ARTIFACTORY: Working with BaGet Server and Artifactory
This article outlines the configuration of the BaGet Server with Artifactory, common known issues that occur due to misconfiguration and debugging steps.
What is the BaGet server?
BaGet is a lightweight NuGet and Symbol server. It is Open-source, cross-platform, and cloud-ready. To work with BaGet and Artifactory, certain prerequisites must be met.
- BaGet Server is up and running. You can refer to this article on how to Install BaGet for more information
- Artifactory server that can access the BaGet server (meaning BaGet’s server IP must be whitelisted on Artifactory server and vise versa)
- When performing Test connection against BaGet server URL from Artifactory’s remote repository, the output should say “Successfully connected to the server”
Configure Artifactory with the BaGet server
Since BaGet hosts NuGet and Symbol packages, thus we can resolve it using the NuGet repository in Artifactory by pointing to the BaGet server as an upstream registry. In order to do that, we need to follow the below steps.
- Create a Remote repository of type NuGet and point it to the BaGet server e.g. “https://bagetServerURL.com”. You can check connectivity by clicking on the “Test” option.
- Additionally, under NuGet Settings, we have to update the “NuGet v3 feed URL” & “Symbol Server URL” with BaGet server references.
Configure NuGet client to pull packages from BaGet
Artifactory provides auto-generated client configuration that we can simply use with the NuGet client.
- Navigate to Application Panel -> Artifactory -> Artifacts and search for the repository name [e.g baget-remote] -> On the top right, click on the Set Me Up button -> Enter Artifactory credentials -> After successful authentication, the steps & properties will be populated accordingly
- You can follow the steps mentioned under the configure tab and configure your NuGet client to resolve packages from the BaGet server via Artifactory
- Below are sample terminal outputs of Nuget client configuration for reference:
$ nuget sources Add -Name Artifactory -Source https://<artURL>/artifactory/api/nuget/v3/<repoName>/index.json -username <userName> -password <token> Package source with Name: Artifactory added successfully. $ nuget setapikey <userName>:<token> -Source Artifactory The API Key '<userName>:<token>' was saved for 'https://<artURL>/artifactory/api/nuget/v3/<repoName>/index.json'
- Below are sample terminal output of package resolution for reference:
$ nuget install Newtonsoft.Json -Source Artifactory Feeds used: https://<artURL>/artifactory/api/nuget/v3/<repoName>/index.json Installing package 'Newtonsoft.Json' to '/installation/path/'. GET https://<artURL>/artifactory/api/nuget/v3/<repoName>/registration-semver2/newtonsoft.json/index.json OK https://<artURL>/artifactory/api/nuget/v3/<repoName>/registration-semver2/newtonsoft.json/index.json 383ms GET https://<artURL>/artifactory/api/nuget/v3/<repoName>/registration-semver2/newtonsoft.json/page/13.0.3/13.0.3.json OK https://<artURL>/artifactory/api/nuget/v3/<repoName>/registration-semver2/newtonsoft.json/page/13.0.3/13.0.3.json 319ms Attempting to gather dependency information for package 'Newtonsoft.Json.13.0.3' with respect to project '/installation/path/', targeting 'Any,Version=v0.0' Gathering dependency information took 8 ms Attempting to resolve dependencies for package 'Newtonsoft.Json.13.0.3' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'Newtonsoft.Json.13.0.3' Resolved actions to install package 'Newtonsoft.Json.13.0.3' GET https://<artURL>/artifactory/api/nuget/v3/<repoName>/registration-semver2/Download/newtonsoft.json/13.0.3 Retrieving package 'Newtonsoft.Json 13.0.3' from 'Artifactory'. OK https://<artURL>/artifactory/api/nuget/v3/<repoName>/registration-semver2/Download/newtonsoft.json/13.0.3 364ms Installed Newtonsoft.Json 13.0.3 from https://<artURL>/artifactory/api/nuget/v3/<repoName>/index.json with content hash . Adding package 'Newtonsoft.Json.13.0.3' to folder '/installation/path/' Added package 'Newtonsoft.Json.13.0.3' to folder '/installation/path/' Successfully installed 'Newtonsoft.Json 13.0.3' to /installation/path/ Executing nuget actions took 3.42 sec
Common/Known Issues
- Below Artifactory 7.81.x versions (SaaS & On-Prem), resolving packages via a virtual repository that associates baget-remote repositories will fail with ‘404 Package Not Found. Thus, it is recommended to resolve this issue via a remote repository as a workaround.
- Suppose the Nuget client cannot retrieve updated versions of existing packages. In that case, you can clear the Nuget client cache using [nuget locals all -clear], perform Zap Cache on the remote repository cache [baget-remote-cache], and try resolving again.
Basic Debugging
Client-side debugging
When it comes to NuGet clients, a simple way is to add a debug flag [-verbosity detailed] to produce verbose client output. This allows us to track all requests being made (in this case, to and from Artifactory) and can help us better understand the full error trace.
Artifactory side debugging
Once we have the error, then we can correlate against Artifactory’s log file [mainly artifactory-service.log, artifactory-request.log & artifactory-request-out.log] with the package name that failed to resolve. This will give us an even clearer picture of what is causing the issue on Artifactory.
Sample logs:
Below is a sample log while publishing a NuGet Package:
==>artifactory-request.log<== 2024-05-09T19:09:11.545Z|1a2a4b6b88a52c15|167.103.24.105|<userName>|GET|/api/nuget/v3/<repoName>/index.json|200|-1|0|19|NuGet Command Line/6.9.1 (Unix 23.4.0.0 2024-05-09T19:09:21.157Z|29eaa7e30ced2bc5|167.103.24.105|<userNAME>|PUT|/api/nuget/<repoName>/|201|-1|0|2366|NuGet Command Line/6.9.1 (Unix 23.4.0.0) ==>artifactory-nuget.log<== 2024-05-09T19:09:21.230Z [jfrt ] [DEBUG] [132e2231e52fee4e] [o.a.a.n.NuGetAddonImpl:377 ] [1e52fee4e|art-exec-3] - Adding to cache repoKey:<repoName>, repoPath:Sitecore.Kernel.10.4.0.nupkg, packageId:Sitecore.Kernel 2024-05-09T19:09:21.241Z [jfrt ] [DEBUG] [132e2231e52fee4e] [.a.a.n.NuGetPkgV2CacheEntry:35] [1e52fee4e|art-exec-3] - Comparison between Sitecore.Kernel:10.4.0 and Sitecore.Kernel:10.4.0 returned value 0 2024-05-09T19:09:21.242Z [jfrt ] [DEBUG] [132e2231e52fee4e] [o.a.a.n.NuGetServiceImpl:311 ] [1e52fee4e|art-exec-3] - Added NuPkg path '<repoName>/Sitecore.Kernel.10.4.0.nupkg ' with id of 'Sitecore.Kernel' and version '10.4.0' to cache.