2

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.

user1416776
  • 99
  • 2
  • 11

2 Answers2

1

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

error404
  • 2,684
  • 2
  • 13
  • 21
0

Thanks a lot for your help. I see your suggestion works but I had when I got your answer already implemented another solution that also works well

I am using the available query language. https://www.jfrog.com/confluence/display/RTF/Artifactory+Query+Language Just before my pipeline declaration in the pipeline file I added

 def artifactory_url = 'https://lote.corp.saab.se:8443/artifactory/api/search/aql'
 def artifactory_search = 'items.find({ "repo":"my_repo"},{"@product.productNumber": 
 {"$match":"produktname"}}).sort({"$desc":["created"]})'
 pipeline
    {

and ...

 stage('Get latest revision') {
                        steps {
                            script {
                                def json_text = sh(script: "curl -H 'X-JFrog-Art-Api:${env.RECIPE_API_KEY}' -X POST '${artifactory_url}' -d '${artifactory_search}' -H 'Content-Type: text/plain' -k", returnStdout: true).trim()
                                def response = readJSON text: json_text
                                VERSION = response.results[0].path;
                                echo "${VERSION}"
                                println 'using each & entry'
                                response[0].each{ entry ->
                                    println 'Key:' + entry.key + ', Value:' + 
                            entry.value
                                }
                            }
                        }
                    }

                    stage('Do relesase on master')
                            {
                            when
                                {
                                    branch "master"
                                }
                            options {
                                    timeout(time: 1, unit: 'HOURS')
                                }
                            steps {
                                script{
                                    RELEASE_SCOPE = input message: 'User input 
                                  required', ok: 'Ok to go?!',
                                    parameters: [
                                       choice(name: 'RELEASE_TYPE', choices: 
                                       'Artifactory\nClearCaseAndArtifactory\nAbort', 
                                        description: 'What is the release scope?'),
                                        string(name: 'VERSION', defaultValue: 
                                    VERSION, description: '''Edit release name please!!''',  
                              trim: false)
                                    ]
                                 }

                                    echo 'Build both RPM and Zip packages'
                                    ... gradlew -Pversion=${RELEASE_SCOPE['VERSION']} clean buildPackages"

                                script {
                                    def artifactory_server = Artifactory.server 'Artifactory'
                                    def buildInfo = Artifactory.newBuildInfo()
                                    def uploadSpec = """{
                                        "files":[
                                                {
                                                  "pattern": "${env.WORKSPACE}/prodname/release/build/distributions/prodname*.*",
                                                  "target": "test_repo/${RELEASE_SCOPE['VERSION']}/",
                                                  "props": "product.name=ProdName;build.name=${JOB_NAME};build.number=${env.BUILD_NUMBER};product.revision=${RELEASE_SCOPE['VERSION']};product.productNumber=produktname"
                                                }
                                            ]
                                        }"""
                                        println(uploadSpec)
                                        artifactory_server.upload(uploadSpec)
                                }

                            }
                        }                       
user1416776
  • 99
  • 2
  • 11