Migrating Artifacts from Azure Artifacts to JFrog Artifactory
Given there isn't an integrated tool to help with the artifact migration, the high-level process has us downloading the artifacts to the build agent pool and uploading each of them from there to Artifactory.
The instructions below should help outline and clarify what needs to be done to ensure a successful migration. Note: The code outlined below is for a Powershell script.
Setup
You will need to create a repository in which you can write a yaml script to carry out the artifact migration. If there is an existing repository that will work, then feel free to update the existing yaml script with the commands outlined below.
Once you have your yaml script created/open, it will be helpful to create variables with all the necessary credentials for the migration.
You will need the following credentials:
1. $organization = "[ORG NAME]"
- The organization name will need to match the name of the Azure DevOps organization in which the artifacts you wish to migrate reside.
2. $project_name = "[PROJECT NAME]"
- The project name will need to match the name of the Azure DevOps project in which the artifacts you wish to migrate reside.
3. $feed_id = "[FEED ID]"
- For information on how to find the correct feed ID, refer to the page found here.
4. $pat = "[PERSONAL ACCESS TOKEN]"
- Make sure you have a valid personal access token with the necessary permissions. Good practice will be to add a task to the script that allows you to connect to Azure Key Vault so you can avoid having the secret values in plain text in the script.
Lastly, you will need to authenticate with Azure DevOps using your pat token. See the code example below:
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$pat"))
Downloading Artifacts from Azure Artifacts
To download artifacts from the Azure Feed, we will need the feed URL. See the below code snippet to see what the feed URL should look like:
"https://feeds.dev.azure.com/$organization/$project/_apis/packaging/feeds/$feedID/packages?api-version=6.1-preview.1"
It would help to save this URL as a variable for future use.
Next, we need to retrieve the list of packages from the Azure feed, like so:
$packagesResponse = Invoke-RestMethod -Uri $feedsUrl -Headers @{Authorization = "Basic $base64AuthInfo"} -Method Get
$packages = $packagesResponse.value
Use the feed URL variable from above for this step.
Loop through each package in the packages variable and get the package name and version number. This information will be used to get the package URL, which will in turn be used to download the package from Azure Artifacts. See below code block for an example:
$packageName = $package.name
$packageVersion = $package.versions[0].version
Write-Host "Copying package $packageName version $packageVersion"
$packageUrl = "https://pkgs.dev.azure.com/$organization/$project/_apis/packaging/feeds/$feedID/nuget/packages/$packageName/versions/$packageVersion/content?api-version=7.0-preview.1"
$packagePath = "$(System.ArtifactsDirectory)/$packageName.$packageVersion.nupkg"
Invoke-RestMethod -Uri $packageUrl -Headers @{Authorization = "Basic $base64AuthInfo"} -OutFile $packagePath -Method Get
Note, the above code example is downloading nuget packages. We can use the file extension as a way to filter what we download.
Migrating to Artifactory
Migrating the artifacts to Artifactory is easiest with the built-in JFrog CLI task. Set up the JfrogCLIV2@1 task as shown below. Choose the correct JFrog platform connection and use the jf rt u
command to upload the artifacts to the desired repository within Artifactory.
- task: JfrogCliV2@1
inputs:
jfrogPlatformConnection: '[YOUR-SERVICE-CONNECTION]'
command: 'jf rt u "*" [YOUR-REPO]/'
workingDirectory: '$(System.ArtifactsDirectory)'
See a full example of the migration script here