The Background: The downstream pipelines do the builds and archive the artifacts to path-1 in Artifactory. The upstream pipeline (caller) needs to copy some artifacts of the downstream to a separate path for delivery with the upstream pipeline build num. The current practice is downloading the artifacts and uploading them but I wonder if I could remotely copy/move them in Artifactory to avoid web traffic.
My question: Is it possible to use the Artifactory plugin to copy artifacts between different paths within the same Artifactory repository? This a reminder that both the source and target paths are within the same Artifactory instance.
pipeline {
agent any
stages {
stage('Copy Artifacts') {
steps {
script {
// Set the source and target paths within the Artifactory repository
def sourceRepo = 'libs-release-local'
def sourcePath = 'path/to/source'
def targetRepo = 'libs-release-local'
def targetPath = 'path/to/target'
// Copy the artifacts using the Artifactory plugin and capture build information
def server = Artifactory.server('artifactory-server-id')
def rtBuildInfo = Artifactory.newBuildInfo()
server.copy {
spec {
fromRepo(sourceRepo)
includePatterns(sourcePath + '/*')
intoRepo(targetRepo)
intoFolder(targetPath)
}
buildInfo rtBuildInfo
}
// Publish the captured build information to Artifactory
server.publishBuildInfo(rtBuildInfo)
}
}
}
}
}
However, when I was trying to use Artifactory.server.copy
, I got below error. Looks like this API doesn't exist at all.
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.jfrog.hudson.pipeline.common.types.ArtifactoryServer.copy() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: [org.jenkinsci.plugins.workflow.cps.CpsClosure2@1712040b]
Possible solutions: any(), any(groovy.lang.Closure), notify(), wait(), every(), grep()
If is it impossible, do you have any ideas on how I could achieve that?
The Jenkins Artifactory plugin does not support this capability, however the new Jenkins JFrog plugin does. The new plugin makes it simple to install and perform JFrog CLI commands.
In the new plugin you could do the following:
tools {
jfrog 'jfrog-cli'
}
jf 'rt cp libs-release-local/path/to/source libs-release-local/path/to/target'
Read more about it here: