I am trying to save build artifacts and pull them into new builds via the upload/download spec portion of the Jenkins Artifactory plugin. Is there a way to grab the "latest" build artifacts?
I see in the Artifactory file spec docs that there should be a "build" element in the download spec where I can specify "LATEST" but that doesn't work, just says "LATEST" not found. Maybe I am not publishing my builds to Artifactory correctly in the first place?
According to this SO question and this GitHub page it appears that sorting by date and grabbing the newest is only supported with the jfrog CLI and not in Jenkins. Others told me that this sort of functionality can be had using the name setter, version number, description setter plugings... but that seems really hacky.
We are using Jenkins 2.60.3 and Artifactory Enterprise 5.4.5.
I could not get this to work at all if I was using "aql", but it works when using "pattern" to find the file(s). When "build" is specified it will grab that build's artifacts only, even if the repo you're pointing at has a bunch a similarly named files (the build metadata in Artifactory takes care of this I guess). Without specifying "build" it would grab all of the matching artifacts.
"build" should be in the build-name/build-number format, but you can leave off the number OR use LATEST in order to grab the latest successful build's artifacts (I tested this by creating a failed build).
Example to illustrate:
- This will download file3 to Dependencies/file3
- Removing "/LATEST" will also download only file3
- Removing the whole "build" line will download all 3 files
# Artifactory Repo: example-repo/
# BuildName: example-build
# example-repo/file1 (from build 1)
# example-repo/file2 (from build 2)
# example-repo/file3 (from build 3)
Download File Spec:
{
"files": [
{
"pattern": "example-repo/file*",
"target": "Dependencies/",
"recursive": "false",
"flat" : "true",
"build" : "example-build/LATEST"
}
]
}
For more info, see the build
keyword in JFrog File Specs document
https://www.jfrog.com/confluence/display/RTF/Using+File+Specs
build [Optional]
If specified, only artifacts of the specified build are downloaded. The 'pattern' property is still taken into account when 'build' is specified. The property format is build-name/build-number. If the build number is not specified, or the keyword LATEST is used for the build number, then the latest published build number is used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With