Jenkins pipeline Jenkins声明性管道,从Artifactory下载最新上传(构建)并获取属性

Jenkins pipeline Jenkins声明性管道,从Artifactory下载最新上传(构建)并获取属性,jenkins-pipeline,artifactory,jenkins-groovy,jfrog-cli,Jenkins Pipeline,Artifactory,Jenkins Groovy,Jfrog Cli,欢迎对这个小问题提出任何建议!:) 可以下载最新版本,但对象不包含任何属性。 是否可以从下载的版本中获取属性 gool是获取一个具有预定义值的输入框,显示以前的版本,即“R1G”,并为用户提供编辑值的选项,即R2A或任何其他值或仅中止(中止意味着没有版本)。 用户还可以选择不使用CH执行任何操作,这将导致超时并最终导致中止 我想 从Artifactory repo下载最新版本 将build.number存储在“def prev_build”中 在要更新的用户输入中显示上一版本(自定义编号)

欢迎对这个小问题提出任何建议!:)

可以下载最新版本,但对象不包含任何属性。 是否可以从下载的版本中获取属性

gool是获取一个具有预定义值的输入框,显示以前的版本,即“R1G”,并为用户提供编辑值的选项,即R2A或任何其他值或仅中止(中止意味着没有版本)。 用户还可以选择不使用CH执行任何操作,这将导致超时并最终导致中止

我想

  • 从Artifactory repo下载最新版本
  • 将build.number存储在“def prev_build”中
  • 在要更新的用户输入中显示上一版本(自定义编号)
''一些代码

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)
“snipet的结尾”


输出为null或我给定的默认值为var,而不是预期的版本号。

是的,首先属性应该出现在您尝试下载的工件中

build.number等是工件的buildinfo.json文件的一部分。这些不是属性,而是某种元数据。此信息将在artifactory的“Builds”菜单下可见。选择回购和构建编号

在最后一列/选项卡上会显示buildinfo。单击该按钮-此文件将保存您需要的与工件对应的所有信息

CI将把build.number和其他信息推送/上传到artifactory


例如,在Jenkins的案例中,当尝试推送到artifactory“捕获并发布构建信息”-->这一步就可以了,非常感谢您的帮助。 我知道你的建议有效,但当我得到你的答案时,我已经实施了另一个同样有效的解决方案

我正在使用可用的查询语言。 就在我添加的管道文件中的管道声明之前

 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
    {
而且

 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)
                                }

                            }
                        }