Search code examples
jenkins-pipelineartifactoryjenkins-groovyjfrog-cli

Jenkins declarative pipe, download latest upload (build) from Artifactory and get properties


Any sugesstions on this litle problem is very welcome! :)

It works fine to download the latest build but the object does not contain any properties. Is it possible to get the properties from a downloaded build?

The gool is to get an inputbox with a predefined value displaying previous version i.e. "R1G" and give the user the option to edit the value to i.e. R2A or any other value or only abort (abort meaning there will be no version). The user also have the option to do nothing withch will led to a timeoute and finaly an abort.

I want to

  • download latest build from Artifactory repo
  • store the build.number in "def prev_build"
  • display the prev_build in an input for the user to be updated (a customized number)

'''some code

echo 'Publiching Artifact.....'
        script{
            def artifactory_server_down=Artifactory.server 'Artifactory'
            def downLoad = """{
            "files": 
                [
                    {
                        "pattern": "reponame/",
                        "target": "${WORKSPACE}/prev/",
                        "recursive": "false",
                        "flat" : "false"
                    }
                ]
            }"""

            def buildInfodown=artifactory_server_down.download(downLoad)
            //Dont need to publish because I only need the properties
            //Grab the latest revision name here and use it again
            echo 'Retriving revision from last uploaded build.....'
            env.LAST_BUILD_NAME=buildInfodown.build.number
            //Yes its a map and I have tried with ['build.number'] but the map is empty
        }
        echo "Previous build name is $env.LAST_BUILD_NAME"  //Will not contain the old (latest)

''' End of snipet

The output is null or the default value I have given the var, not the expected version number.


Solution

  • Yes, firstly the properties should be present in the artifacts you are trying to download.

    The build.number etc are part of the buildinfo.json file of the artifacts. these are not properties but metadata of some kind. this info would be visible under "Builds" menu in artifactory. Select the repo and build number.

    At the last column/tab there would be buildinfo. Click on that - this file will hold all the info you need corresponding to the artifacts.

    The build.number and other info will be pushed/uploaded to artifactory by the CI.

    For example in case of Jenkins there is an option available when trying to push to artifactory "Capture and publish build info" --> this step does the work