Jenkins Artifactory plugin - grabbing latest artif

2019-06-28 04:15发布

问题:

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.

回答1:

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"
        }
    ]
 }