When creating a new repository in Artifactory from the UI, you’ll have to manually configure the replication settings. If it’s a local repository, you’ll have to specify the URL of the repository to which you’ll be pushing content. If it’s a remote repository proxying another Artifactory instance, you’ll have to configure your cron expression to set the frequency of replication.
If you’d like to automate the process of creating a local repository and replicating it to a remote repository in another Artifactory instance, you can do so by using the following REST APIs in sequence:
1. Run the Create Repository REST API. This query consumes a JSON object that contains your repository configuration. It will look like this:
{ "key" : "libs-release-local", "description" : "Local repository for in-house libraries", "notes" : "", "includesPattern" : "**/*", "excludesPattern" : "", "repoLayoutRef" : "maven-2-default", "enableNuGetSupport" : false, "enableGemsSupport" : false, "enableNpmSupport" : false, "enableDebianSupport" : false, "debianTrivialLayout" : false, "enablePypiSupport" : false, "enableDockerSupport" : false, "checksumPolicyType" : "client-checksums", "handleReleases" : true, "handleSnapshots" : false, "maxUniqueSnapshots" : 0, "snapshotVersionBehavior" : "unique", "suppressPomConsistencyChecks" : false, "blackedOut" : false, "propertySets" : [ "GTID", "artifactory" ], "archiveBrowsingEnabled" : false, "calculateYumMetadata" : false, "yumRootDepth" : 0, "rclass" : "local" }
2. Run the Set Repository Replication Configuration to configure your replication. This query consumes a JSON object to configure your replication. It will look like this:
{ "url" : "{destination URL}", "socketTimeoutMillis" : 15000, "username" : "{destination URL username (if needed)}", "password" : "{destination URL password(if needed)}", "enableEventReplication" : false, "enabled" : false, "cronExp" : "0 0 /4 * * ?", "syncDeletes" : false, "syncProperties" : true, "repoKey" : "libs-release-local" }
If you’d like to format a JSON to create a remote repository and it’s replication JSON, use the Repository Configuration and Get Repository Replication Configuration REST APIs for existing repositories.